Nacos-01 Spring cloud 服务配置与调用(postgresql & spring cloud)
前提 serviceA 调用 serviceB
配置
<-- 父工程引入-->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>2.2.0.RELEASE</version>
</dependency>
</dependencies>
</dependencyManagement>
<-- serviceB -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<version>2.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
<version>2.2.0.RELEASE</version>
</dependency>
<-- serviceA 按理说子工程不需要版本号,估计是父工程的版本不支持? 后续有时间再调查-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<version>2.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
<version>2.2.0.RELEASE</version>
</dependency>
<-- openfeign-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
seriviceA Application
@EnableFeignClients
@EnableDiscoveryClient
@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class}) // 不需要数据库
serviceB Applicaiton
@EnableDiscoveryClient
@SpringBootApplication
serviceA bootstrap.yml
spring:
application:
name: service-A
cloud:
nacos:
discovery:
server-addr: http://xxx.xxx.xxx.xx:8848
server:
port: 7294
management:
endpoints:
web:
exposure:
include: '*'
serviceB bootstrap.yml
spring:
application:
name: service-B
cloud:
nacos:
discovery:
server-addr: http://xxx.xxx.xxx.xx:8848
config:
server-addr: http://xxx.xxx.xxx.xx:8848
file-extension: yaml
server:
port: 7293
management:
endpoints:
web:
exposure:
include: '*'
~~~yml
### serviceB application.yml
~~~yml
spring:
profiles:
active: dev
nacos 配置 serviceB 配置信息service-B-dev.yaml
spring:
datasource:
name: pg
url: jdbc:postgresql://xxx.xxx.xxx.xx/postgres
username:
password:
# 使用druid数据源
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: org.postgresql.Driver
mybatis-plus: # 以下均可删除,是mybatis-plus 的一些配置
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 这个是打印sql日志的,可以删除
type-handlers-package: com.xxx.xxx.typehandlers # 这个是类型转换需要的,可以删除
global-config: # 这些是配置全局默认值的,可以删除
db-config:
logic-delete-field: deleteStatus
logic-delete-value: 1
logic-not-delete-value: 0
~~~yaml
通过知识/经验的分享,节省开发者的时间.