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

How to build Micro Services based on java SpringCloud

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

Share

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

This article mainly introduces "how to build micro-services based on java SpringCloud". In daily operation, I believe many people have doubts about how to build micro-services based on java SpringCloud. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the questions of "how to build micro-services based on java SpringCloud". Next, please follow the editor to study!

Development environment

1 、 jdk1.8

2. Springboot 2.0.6.RELEASE and SpringCloud related services

3. Idea + maven

Code sample itstack-demo-ddd-case | DDD-based microservice {this code has been demonstrated in the previous section} 1itstack-demo-ddd-case

2 └── src

3 ├── main

4 │ ├── java

5 │ │ └── org.itstack.demo

6 │ │ ├── application

7 │ ├── MallRuleService.java

8 │ └── MallTreeService.java

9 │ │ ├── domain

10 │ ├── rule

11 │ ├── model

12 │ ├── aggregates

13 │ └── UserRichInfo.java

14 │ └── vo

15 │ ├── DecisionMatter.java

16 │ ├── EngineResult.java

17 │ ├── TreeNodeInfo.java

18 │ ├── TreeNodeLineInfo.java

19 │ └── UserSchool.java

20 │ ├── repository

21 │ └── IRuleRepository.java

22 │ └── service

23 │ ├── engine

24 │ ├── impl

25 │ └── EngineFilter.java

26 │ ├── logic

27 │ ├── impl

28 │ └── LogicFilter.java

29 │ └── MallRuleServiceImpl.java

30 │ └── tree

31 │ ├── model

32 │ │ ├── aggregates

33 │ └── TreeCollect.java

34 │ │ └── vo

35 │ │ ├── TreeInfo.java

36 │ │ └── TreeRulePoint.java

37 │ ├── repository

38 │ │ └── ITreeRepository.java

39 │ └── service

40 │ └── MallTreeServiceImpl.java

41 │ │ ├── infrastructure

42 │ ├── common

43 │ └── Constants.java

44 │ ├── dao

45 │ ├── RuleTreeDao.java

46 │ ├── RuleTreeNodeDao.java

47 │ └── RuleTreeNodeLineDao.java

48 │ ├── po

49 │ ├── RuleTree.java

50 │ ├── RuleTreeConfig.java

51 │ ├── RuleTreeNode.java

52 │ └── RuleTreeNodeLine.java

53 │ ├── repository

54 │ ├── cache

55 │ └── RuleCacheRepository.java

56 │ ├── mysql

57 │ ├── RuleMysqlRepository.java

58 │ └── TreeMysqlRepository.java

59 │ ├── RuleRepository.java

60 │ └── TreeRepository.java

61 │ └── util

62 │ └── CacheUtil.java

63 │ │ ├── interfaces

64 │ ├── dto

65 │ ├── DecisionMatterDTO.java

66 │ └── TreeDTO.java

67 │ └── DDDController.java

68 │ │ └── DDDApplication.java

69 │ └── resources

70 │ ├── mybatis

71 │ └── application.yml

72 └── test

73 └── java

74 └── org.itstack.demo.test

75 └── ApiTest.java

Itstack-demo-ddd-eureka-server | Service registration and discovery 1itstack-demo-ddd-eureka-server

2 └── src

3 ├── main

4 │ ├── java

5 │ │ └── org.itstack.demo

6 │ │ └── EurekaServerApplication.java

7 │ └── resources

8 │ └── application.yml

9 └── test

10 └── java

11 └── org.itstack.demo.test

12 └── ApiTest.java

EurekaServerApplication.java | start the service

1Candle *

2 * official account of Wechat: bugstack wormhole stack | focus on original technology project case

3 * Forum: http://bugstack.cn

4 * Create by paid commissar on @ 2019

5 * /

6@SpringBootApplication

7@EnableEurekaServer

8public class EurekaServerApplication {

nine

10 public static void main (String [] args) {

11 SpringApplication.run (EurekaServerApplication.class, args)

12}

thirteen

14}

Application.yml | Service configuration

1server:

2 port: 8989

three

4eureka:

5 instance:

6 hostname: localhost

7 client:

8 registerWithEureka: false

9 fetchRegistry: false

10 serviceUrl:

11 defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/

twelve

13spring:

14 application:

15 name: itstack-demo-ddd-eureka-server

Itstack-demo-ddd-feign | caller, which calls 1itstack-demo-ddd-feign through the API API

2 └── src

3 ├── main

4 │ ├── java

5 │ │ └── org.itstack.demo

6 │ │ ├── domain

7 │ └── TreeDTO.java

8 │ │ ├── service

9 │ └── MallService.java

10 │ │ ├── web

11 │ └── FeignController.java

12 │ │ └── FeignApplication.java

13 │ └── resources

14 │ └── application.yml

15 └── test

16 └── java

17 └── org.itstack.demo.test

18 └── ApiTest.java

MallService.java | call API through registration

1Candle *

2 * official account of Wechat: bugstack wormhole stack | focus on original technology project case

3 * Forum: http://bugstack.cn

4 * Create by paid commissar on @ 2019

5 * /

6@FeignClient (value = "itstack-demo-ddd-case")

7public interface MallService {

eight

9 @ RequestMapping (value = "/ api/tree/queryTreeSummaryInfo", method = RequestMethod.POST)

10 Object queryTreeSummaryInfo (@ RequestBody TreeDTO request)

eleven

12}

FeignApplication.java | start the service

1Candle *

2 * official account of Wechat: bugstack wormhole stack | focus on original technology project case

3 * Forum: http://bugstack.cn

4 * Create by paid commissar on @ 2019

5 * /

6@SpringBootApplication

7@EnableEurekaClient

8@EnableDiscoveryClient

9@EnableFeignClients

10public class FeignApplication {

eleven

12 public static void main (String [] args) {

13 SpringApplication.run (FeignApplication.class, args)

14}

fifteen

16}

Application.yml | Service configuration

1server:

2 port: 9090

three

4spring:

5 application:

6 name: itstack-demo-ddd-feign

seven

8eureka:

9 client:

10 serviceUrl:

11 defaultZone: http://localhost:8989/eureka/

Itstack-demo-ddd-zuul | Gateway routing component 1itstack-demo-ddd-zuul

2 └── src

3 ├── main

4 │ ├── java

5 │ │ └── org.itstack.demo

6 │ │ └── ZuulApplication.java

7 │ └── resources

8 │ └── application.yml

9 └── test

10 └── java

11 └── org.itstack.demo.test

12 └── ApiTest.java

ZuulApplication.java | start the service

1Candle *

2 * official account of Wechat: bugstack wormhole stack | focus on original technology project case

3 * Forum: http://bugstack.cn

4 * Create by paid commissar on @ 2019

5 * /

6@SpringBootApplication

7@EnableZuulProxy

8@EnableEurekaClient

9@EnableDiscoveryClient

10public class ZuulApplication {

eleven

12 public static void main (String [] args) {

13 SpringApplication.run (ZuulApplication.class, args)

14}

fifteen

16}

Application.yml | Service configuration {this case is a static route, which can be developed as a dynamic route on demand.

1server:

2 port: 9191

three

4spring:

5 application:

6 name: itstack-demo-ddd-zuul

seven

8eureka:

9 client:

10 serviceUrl:

11 defaultZone: http://localhost:8989/eureka/

12zuul:

13 routes:

14 api-a:

15 path: / route-a/**

16 serviceId: itstack-demo-ddd-feign

seventeen

Test verification

Start sequentially; itstack-demo-ddd-eureka-server, itstack-demo-ddd-case {can simulate starting multiple}, itstack-demo-ddd-feign, itstack-demo-ddd-zuul

Visit; http://localhost:8989/ | Service center

Access: http://localhost:9191/route-a/api/queryTreeSummaryInfo?treeId=10001 | call the DDD service API through gateway routing

At this point, the study on "how to build micro services based on java SpringCloud" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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