Springcloud Series Research---Eureka service registration

Source: Internet
Author: User

By annotating @enableeurekaclient, you indicate that you are a eurekaclient, also a provider of services.

The startup class code is as follows:

1  PackageCom.cloud.microservice.demo;2 3 Importorg.springframework.boot.SpringApplication;4 Importorg.springframework.boot.autoconfigure.SpringBootApplication;5 Importorg.springframework.cloud.client.discovery.EnableDiscoveryClient;6 Importorg.springframework.cloud.netflix.eureka.EnableEurekaClient;7 ImportOrg.springframework.context.annotation.ComponentScan;8 9 @SpringBootApplicationTen @EnableDiscoveryClient One @EnableEurekaClient A@ComponentScan ("Com.cloud.microservice.demo") -  Public classdemoproviderapplication { -  the      Public Static voidMain (string[] args) { -Springapplication.run (demoproviderapplication.class, args); -     } -}

In order to separate the start class and interface, I created a new provider package here, put the rest interface Userprovider.java under this path, the project structure is as follows:

The Userprovider.java code is as follows:

1  PackageCom.cloud.microservice.demo.provider;2 3 Importorg.springframework.cloud.netflix.feign.FeignClient;4 Importorg.springframework.web.bind.annotation.RequestMapping;5 ImportOrg.springframework.web.bind.annotation.RequestMethod;6 ImportOrg.springframework.web.bind.annotation.RequestParam;7 ImportOrg.springframework.web.bind.annotation.RestController;8 9@FeignClient (name = "Ms-demo-provider")Ten @RestController One@RequestMapping ("/demo/user") A  Public classUserprovider { -  -@RequestMapping (value= "/1.0/findall", method=requestmethod.get) the      Publicstring FindAll (@RequestParam string name) -     { -         return"Hello,this is" +name; -     } +}

The configuration file application.yml is as follows: Registerwitheureka indicates whether to register itself to the Eureka server, because the current application is Eureka Service, in order to see the registration information on the Eureka service, this is set to true;fetchregistry representation Whether to obtain registration information from the Eureka Server.

1 Server:2port:80903 4 Eureka:5 instance:6 Hostname:localhost7 Client:8Registerwitheureka:true9Fetchregistry:falseTen serviceurl: OneDefaultzone:http://${eureka.instance.hostname}:9090/eureka/ A  - Spring: - Application: theName:ms-demo-provider

Start the project, open the http://localhost:9090, that is, the Eureka server URL, you will find a service is registered in the service, the service name is Ms-demo-provider, the port is 8090.

Enter Http://localhost:8090/demo/user/1.0/findAll?name=helloworld in the browser address bar, for example, to indicate that the service interface is functioning properly.

Springcloud Series Research---Eureka service registration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.