Regarding the environment construction part, please refer to: nacos as a complete use case of configuration center and service registration center
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
server.port=8070
spring.application.name=server-provider
spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
Sample code for the main startup class
@SpringBootApplication
@EnableDiscoveryClient
public class NacosProviderApplication {
public static void main(String[] args) {
SpringApplication.run(NacosProviderApplication.class, args);
}
@RestController
class EchoController {
@RequestMapping(value = "/echo/{string}", method = RequestMethod.GET)
public String echo(@PathVariable String string) {
return "Hello Nacos Discovery " + string;
}
}
}
Then start the main startup class. Note: The main startup class has at least one restful style request resource, otherwise it will easily fail because it is an empty service
After starting the project, you can find the explanation in the service list as follows!