我们来建立一个子模块并注册到EurekaServer
postman 依赖
<dependencies>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc14</artifactId>
<version>10.2.0.4.0</version>
</dependency>
<!-- 加入文档生成的支持 (swagger) -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.7.0</version>
</dependency>
</dependencies>
配置
server:
port: 30521
spring:
application:
name: POSTMAN
datasource:
url: jdbc:oracle:thin:@192.168.66.226:1521:znjt
username: znjtpostman
password: znjtpostman
driver-class-name: oracle.jdbc.OracleDriver
mybatis:
mapper-locations: classpath*:brilliance/znjt/business/postman/mappers/**/*.xml
eureka:
client:
service-url:
defaultZone: http://localhost:30520/eureka/
启动类上加入eureka服务端注解,swagger注解 启动!!成功。。(里面就是一些查询接口)
下面我们就要考虑一下把所有子模块的项目文件放到一个服务上这样是不是更好管理
让我们来建立一个configServer统一配置中心服务端
建立好子模块加入configserver 和 eureka客户端的依赖
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
</dependencies>
先去启动项加入几个注解
@SpringBootApplication
@EnableEurekaClient
@EnableConfigServer
配置文件这里采取本地配置路径
server:
port: 30530
eureka:
client:
service-url:
defaultZone: http://localhost:30520/eureka/
spring:
application:
name: CONFIGSERVER
profiles:
active:
- native
cloud:
config:
server:
native:
search-locations:
- D:/nativeconfig
往配置的目录扔个配置文件,启动项目试着读取下看看,嗯不错读取成功,看来可以正常运行
下面我们来改造一下postman 让配置文件放在配置中心
首先在postman加入依赖配置中心服务端的依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-client</artifactId>
</dependency>
然后去改变postman的配置文件
把文件名改成bootstrap(让他先读取),内容
spring:
application:
name: POSTMAN
cloud:
config:
discovery:
enabled: true
service-id: CONFIGSERVER
profile: dev
eureka:
client:
service-url:
defaultZone: http://localhost:30520/eureka/
配置中心配置
server:
port: 30521
spring:
application:
name: POSTMAN
datasource:
url: jdbc:oracle:thin:@192.168.66.226:1521:znjt
username: znjtpostman
password: znjtpostman
driver-class-name: oracle.jdbc.OracleDriver
mybatis:
mapper-locations: classpath*:brilliance/znjt/business/postman/mappers/**/*.xml
然后我们来运行一下测试下接口ok没问题