1.服务注册
1.1.在pom.xml中添加nacos的依赖
<!--nacos客户端-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
1.2.在springboot启动类添加nacos注解
@EnableDiscoveryClient
2.使用配置中心
2.1添加Nacos 配置中心依赖
<!-- Nacos 配置中心 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
2.2创建配置文件
注意:要创建的文件名为: 微服务名-dev/pro/test .yml
image.png
#服务端口号
server:
port: 9110
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
type: com.alibaba.druid.pool.DruidDataSource
url: jdbc:mysql://localhost:3306/spring_security_db?serverTimezone=UTC&useUnicode=true&characterEncoding=utf8&useSSL=false
username: root
password: 1234
main:
allow-bean-definition-overriding: true
mybatis-plus:
mapper-locations: classpath*:/mapper/**/**Mapper.xml
#数据库主键生成策略
global-config:
db-config:
id-type: uuid
# 关闭MP3.0自带的banner
banner: false
configuration:
# 这个配置会将执行的sql打印出来,在开发或测试的时候可以用
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
# 返回类型为Map,显示null对应的字段
call-setters-on-nulls: true