Bläddra i källkod

新增后台管理系统网关

chenweida 7 år sedan
förälder
incheckning
48068345ec

+ 100 - 0
manage-gateway/pom.xml

@ -0,0 +1,100 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>com.yihu.jw</groupId>
    <artifactId>svr-lib-parent-pom</artifactId>
    <version>1.0.0</version>
    <relativePath>../svr-lib-parent-pom/pom.xml</relativePath>
  </parent>
  <artifactId>manage-gateway</artifactId>
  <packaging>jar</packaging>
  <version>1.0.0</version>
  <dependencies>
    <dependency>
      <groupId>com.yihu.jw</groupId>
      <artifactId>common-swagger</artifactId>
    </dependency>
    <dependency>
      <groupId>com.yihu.jw</groupId>
      <artifactId>common-rest-model</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-tomcat</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-jdbc</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-aop</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-eureka</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-config</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-feign</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-hystrix</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-zuul</artifactId>
    </dependency>
    <!--zipkin支持分布式追踪系统-->
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-sleuth</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-sleuth-zipkin</artifactId>
    </dependency>
    <!--<dependency>-->
    <!--<groupId>org.springframework.cloud</groupId>-->
    <!--<artifactId>spring-cloud-starter-bus-kafka</artifactId>-->
    <!--</dependency>-->
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-annotations</artifactId>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-core</artifactId>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-databind</artifactId>
    </dependency>
  </dependencies>
</project>

+ 18 - 0
manage-gateway/readme.MD

@ -0,0 +1,18 @@
此项目是后台管理系统的的网关项目
    网关调用微服务利用fegin(spring-cloud-starter-feign)
    
查看服务健康需要添加以下支持
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
    
    localhost:8088/health
    
刷新配置
在有需要刷新配置的地方的类加上注解
    @RefreshScope
    访问以下路径刷新配置
    curl -X POST http://localhost:8088/refresh

+ 27 - 0
manage-gateway/src/main/java/com/yihu/jw/manage/SvrManageAppliction.java

@ -0,0 +1,27 @@
package com.yihu.jw.manage;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
/**
 * Created by chenweida on 2017/5/31.
 */
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class})
//@SpringBootApplication
@EnableDiscoveryClient//服务注册到发现服务
@EnableHystrix //启动断路器
@EnableZuulProxy //启动zuul代理 路由
@EnableFeignClients //声名式的客户端
@EnableCircuitBreaker
public class SvrManageAppliction {
    public static void main(String[] args) {
        SpringApplication.run(SvrManageAppliction.class, args);
    }
}

+ 26 - 0
manage-gateway/src/main/java/com/yihu/jw/manage/config/MvcConfig.java

@ -0,0 +1,26 @@
package com.yihu.jw.manage.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
/**
 * Created by chenweida on 2017/5/31.
 */
@Configuration
public class MvcConfig extends WebMvcConfigurerAdapter {
    /**
     * 支持跨域问题
     * 资料:http://blog.csdn.net/dalangzhonghangxing/article/details/51994812
     * @param registry
     */
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("*")
                .allowCredentials(true)
                .allowedMethods("GET", "POST", "DELETE", "PUT")
                .maxAge(3600);
    }
}

+ 57 - 0
manage-gateway/src/main/resources/application.yml

@ -0,0 +1,57 @@
##如果有配置服务的话,远程服务器和本地服务器配置不一致的情况下,优先远程的为主
spring:
  application:
    name:  manage-gateway  ##注册到发现服务的id 如果id一样 eurika会自动做负载
##开启feign断路器
feign:
  hystrix:
    enabled: true
management:
  security:
    enabled: false  ##关闭 refresh的权限认证
#zuul 默认会代理所有的微服务  路径 /{appliction.name}/**
zuul:
  ignored-services: '*'  ##忽略全部的代理  忽略单个微服务   ignored-services: svr-base 多个逗号分割
  routes:
    svr-base: /base/**  ##svr-base方向代理到/base下多层级的路径
#    svr-base:    这种方式和  svr-base: /base/**  一样  svr-base可以随便写 唯一即可
#      path: /base/**  path是代理后的路径
#      serviceId: svr-base  serviceId是微服务name
#   svr-base: 这种方式和 上面一样 就是serviceId改成具体的url 但是这种配置方法不能利用eurika的负载均衡
#     path: /base/**
#     url: http://localhost:10020/
#svr-base: 这边是微服务ID  配置负载均衡
#  ribbon:
#    listOfService: http://localhost:10020/,http://localhost:10021/
---
spring:
  profiles: jwdev
#  cloud:
#    stream:
#      kafka:
#        binder:
#          brokers: 172.17.110.201
#          defaultBrokerPort: 9092
#          zkNodes: 172.17.110.201
#          defaultZkPort: 2181
#          replicationFactor: 1
---
spring:
  profiles: jwtest
---
spring:
  profiles: jwprod

+ 8 - 0
manage-gateway/src/main/resources/banner.txt

@ -0,0 +1,8 @@
 __  __                                         _____       _
 |  \/  |                                       / ____|     | |
 | \  / | __ _ _ __   __ _  __ _  ___          | |  __  __ _| |_ _____      ____ _ _   _
 | |\/| |/ _` | '_ \ / _` |/ _` |/ _ \         | | |_ |/ _` | __/ _ \ \ /\ / / _` | | | |
 | |  | | (_| | | | | (_| | (_| |  __/         | |__| | (_| | ||  __/\ V  V / (_| | |_| |
 |_|  |_|\__,_|_| |_|\__,_|\__, |\___|          \_____|\__,_|\__\___| \_/\_/ \__,_|\__, |
                            __/ |                                                   __/ |
                           |___/                                                   |___/

+ 46 - 0
manage-gateway/src/main/resources/bootstrap.yml

@ -0,0 +1,46 @@
##优先读取 boostarap配置 然后在读取application。yml的配置
spring:
  #从发现服务里面取配置服务的信息
  cloud:
    config:
      failFast: false ##启动快速失败 即链接不到配置服务就启动失败
      username: jw
      password: jkzl
      discovery:
        enabled: true ##使用发现服务
        service-id: svr-configurations ##配置服务的名字
---
spring:
  profiles: jwdev
eureka:
  client:
    serviceUrl:
      #http://账号:密码@127.0.0.1:8761/eureka/
      defaultZone: http://jw:jkzl@127.0.0.1:8761/eureka/
---
spring:
  profiles: jwtest
eureka:
  client:
    serviceUrl:
      #http://账号:密码@127.0.0.1:8761/eureka/
      defaultZone: http://jw:jkzl@127.0.0.1:8761/eureka/
---
spring:
  profiles: jwprod
eureka:
  client:
    serviceUrl:
      #http://账号:密码@127.0.0.1:8761/eureka/
      defaultZone: http://jw:jkzl@127.0.0.1:8761/eureka/

+ 1 - 0
readme.MD

@ -16,6 +16,7 @@
     common-lib-parent-pom    common公共工程的maven父pom
     jw-lib-parent-pom   jw业务公共工程的maven父pom 
     web-gateway 对外的接口网关
     manage-gateway 基卫后台管理系统的接口网关
     .gitignore   项目提交忽略配置文件
     
项目运行

+ 1 - 0
svr-lib-parent-pom/pom.xml

@ -46,6 +46,7 @@
        <!--网关-->
        <module>../web-gateway</module><!--web网关-->
        <module>../manage-gateway</module><!--后台管理系统网关-->
    </modules>
    <properties>

+ 1 - 0
web-gateway/pom.xml

@ -13,6 +13,7 @@
    <groupId>com.yihu.jw</groupId>
    <artifactId>web-gateway</artifactId>
    <version>1.0.0</version>
    <dependencies>
        <dependency>
            <groupId>com.yihu.jw</groupId>