Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the internal service invocation methods of Springboot

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you what are the internal service invocation methods of Springboot. I hope you will get something after reading this article. Let's discuss it together.

Eureka registered services call each other 1. Requesting party

Start the class to add comments and scan all services in Eureka

@ SpringBootApplication@EnableEurekaClient@EnableFeignClientspublic class LoginServiceApplication {public static void main (String [] args) {new SpringApplicationBuilder (LoginServiceApplication.class) .web (true) .run (args);}}

Pom.xml add package (version number is selected according to actual)

Org.springframework.cloud spring-cloud-starter-feign 1.4.6.RELEASE

Create an interface class

FeignClient (name= "hello-service") / / spring service namepublic interface FeignVehicle {@ RequestMapping (value= "/ hello", method = RequestMethod.GET) @ ResponseBody public List hello (@ RequestParam Map params);}

The implementation class injects this interface class

@ AutowiredFeignVehicle feignVehicle

When you use it, you can directly follow the normal calling mode.

Map map = new HashMap (); feignVehicle.hello (map)

When the cross-service call occurs, the token information is not available, and an interceptor is added to the sender.

Receiving party

Request startup class

@ SpringBootApplication@EnableEurekaClientpublic class HelloServiceApplication {public static void main (String [] args) {new SpringApplicationBuilder (HelloServiceApplication.class) .web (true) .run (args);}}

Request Controller

@ Controller@RequestMapping ("/ hello") public class HelloController {@ RequestMapping (value= "/ hello", method = RequestMethod.GET) @ ResponseBody public List hello (@ RequestParam Map queryParam) {return null;}} Multi-modularization, background of inter-service invocation

Product service, as a server, provides an external communication Fegin interface ProductClient, which is placed under the com.imooc.product.client jar package.

The order service, as the client, refers to the above jar directly, uses ProductClient, and reports the following error after starting the main class:

Solution.

When you are multi-modular, you should add the comments circled below to the order main class so that the package can be scanned after startup.

After reading this article, I believe you have a certain understanding of "what are the internal service invocation methods of Springboot". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report