Spring boot and Spring clound microservice project construction process--cainiao Xiaohui

Spring boot and Spring clound microservice project construction process


  • Preface: This blog post is used to record the construction process of Spring boot and Spring clound projects, including simple database query, reverse engineering, and common pom dependencies. Completely configure the Spring clound project microservice project.
    Note: Please install the module after importing pom dependencies.
    enter description here

1. Create the parent parent to provide the basic jar package

  1. Create maven moudule
    enter description here
  2. Specify the parent type to be the pom type, and add related dependency
    parent dependency one (1)

2. Create common to provide public jar packages, entity classes, tools, etc. for the project

  1. Create maven type module
    enter description here

  2. Add parent class dependency reference and project need jar package
    common dependency one (2)

  3. Add the reverse engineering configuration file generatorConfig.xml generatorConfig.xml under resources
    Two (1)
    enter description here

  4. Create a mappers directory under resources to store mapper.xml.
    enter description here

  5. Run reverse engineering as shown in the figure to get mapper, pojo, mappers
    enter description here
    enter description here

  6. Add the required tools, such as
    enter description here


Three, create a server to provide spring cloud services

  1. Create spring boot module
    enter description here
    enter description here
    enter description here

  2. Add pom dependency and introduce the parent package
    server dependency one (3)

  3. Run the main class to add @EnableEurekaServer annotation
    enter description here

  4. Configure application.properties service

#端口
server.port=8000
#application.name
spring.application.name=ttl_server

#通过eureka.client.registerWithEureka:false和fetchRegistry:false来表明自己是一个eureka server.
eureka.instance.hostname=localhost
#registerWithEureka表示是否注册自身到eureka服务器
eureka.client.register-with-eureka=false
#fetchRegistry表示是否从eureka服务器获取注册信息。
eureka.client.fetch-registry=false
eureka.client.service-url.defaultZone=http://${eureka.instance.hostname}:${server.port}/eureka/


Fourth, create api to write project source code

  1. Create a spring boot module (the steps are the same as the server creation)

  2. Add pom and introduce common as a jar package into
    api dependency one (4)

  3. Run the main class to add client annotations

@EnableEurekaClient
@EnableFeignClients
@ComponentScan("com.zhiyou")
@MapperScan("com.zhiyou.mapper")

enter description here

  1. Configure application.properties client
#设置客户端
server.port=8001
spring.application.name=ttl_api
eureka.client.service-url.defaultZone=http://localhost:8000/eureka/

#连接数据库
spring.datasource.url=jdbc:mysql://120.27.244.176:3306/hospital?useUnicode=true&characterEncoding=UTF-8&useSSL=false
spring.datasource.username=root
spring.datasource.password=HBQ521521cf*
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

#设置mapper.xml文件扫描位置
mybatis.mapper-locations=classpath:/mappers/*.xml

#给实体类包起别名
mybatis.type-aliases-package=com.zhiyou.pojo


Five, test program operation

  1. Write a test program, query the contents of the table
    enter description here
  • controller
    enter description here
  • serviceImpl
    enter description here
  1. Start the server first, then start the api.
  2. Browser input "http://localhost:8001/found.action" test
    enter description  here

Guess you like

Origin blog.csdn.net/qq_39231769/article/details/103217028