5、分布式组件Nacos注册中心

修改mall-common的pom.xml文件,引入 Nacos Discovery Starter。
 <dependency>
     <groupId>com.alibaba.cloud</groupId>
     <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
 </dependency>
配置 Nacos Server 地址(相应模块application.properties)
spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
使用 @EnableDiscoveryClient 注解开启服务注册与发现功能
 @SpringBootApplication
 @EnableDiscoveryClient
 public class ProviderApplication {

 	public static void main(String[] args) {
 		SpringApplication.run(Application.class, args);
 	}

 	@RestController
 	class EchoController {
 		@GetMapping(value = "/echo/{string}")
 		public String echo(@PathVariable String string) {
 				return string;
 		}
 	}
 }

猜你喜欢

转载自blog.csdn.net/KAIZ_LEARN/article/details/107666272