2
springAlibaba实践(9)----Nacos项目配置
source link: http://www.blogjava.net/zzsuje/archive/2022/05/06/450737.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
springAlibaba实践(9)----Nacos项目配置
9.1. 依赖引入 Nacos Discovery Starter
首先,修改 common中的pom.xml 文件。
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
9.2.使用 @EnableDiscoveryClient 注解开启服务注册与发现功能首先,修改 common中的pom.xml 文件。
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
@SpringBootApplication
@MapperScan("com.yxj.gulimall.coupon.dao")
@EnableDiscoveryClient
public class GulimallCouponApplication {
public static void main(String[] args)
{
SpringApplication.run(GulimallCouponApplication.class, args);
}
}
@MapperScan("com.yxj.gulimall.coupon.dao")
@EnableDiscoveryClient
public class GulimallCouponApplication {
public static void main(String[] args)
{
SpringApplication.run(GulimallCouponApplication.class, args);
}
}
3.在应用的common中的application.yml 配置文件中配置 Nacos Server 地址和微服务名称
spring:
application:
name: gulimall-coupon
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://192.168.100.106:3306/gulimall_sms?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
username: root
password: root
cloud:
nacos:
discovery:
server-addr: 192.168.100.106:8848
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK