1024programmer Blog Spring-cloud project construction process_tc cloud_JJD_CXY’s blog

Spring-cloud project construction process_tc cloud_JJD_CXY’s blog

class=”markdown_views prism-atom-one-dark”>

Spring-Cloud project construction

1. Course Introduction

1. Basic introduction to HRM project

2. HRM project prototype (focus)

3. System management backend construction (focus)

4. Mybatis-plus integration (focus)

5. Swagger integration
6. Gitee management project
2. Basic introduction of the project
2.1. Project background
People who are looking for a job and people who want to learn
Now the pressure of social competition It is getting bigger and bigger, and many fresh graduates are not directly qualified for certain types of jobs after graduation, or some people who have already worked gradually lose their ability to study, which eventually leads to unemployment and cannot be re-employed.
Recruiting units
Although there are many job seekers, many of them are not qualified enough to meet the requirements of the employers. They expect to be able to use them as soon as they are recruited, so it is necessary to train and screen job candidates.
Training Institutions
Although many training institutions have the ability to train talents, their market ability is relatively poor, and they cannot find suitable trainees, so that they can find jobs through training

Because of the above three types of scenarios, we have developed a source code manpower comprehensive platform, so that job seekers can choose courses from specific institutions to study, participate in the recruitment published by the platform, and participate in some activities. Let recruiting units settle in and post jobs for recruitment, and even entrust training institutions to train suitable talents. For configuration institutions, they can publish courses, absorb students to complete their studies and obtain commercial value by charging tuition fees.

2.2. Functional modules
Insert picture description here

2.3. Project Prototype
Learn more about the functions of the project through the project prototype, including: portal home page, course search page, personal center, etc. Refer to “Project Prototype”
3. Project Technical Architecture
3.1. Technology Architecture
Insert picture description here

The project adopts the mainstream front-end and back-end separation mode. The front-end is divided into system management front-end and portal front-end (job site, course site, user center, etc.).

3.2. Technology stack
The system management front-end adopts the technology stack
Node.js, Vue.js, Npm, WebPack, Vue Cli, Element UI, Easy Mock and so on.
 The portal front-end technology stack is
Html, css, js, jquery and so on.
The backend adopts microservice architecture technology stack as
microservice architecture: split N multiple services according to their functions, and each service can be independently selected, developed, deployed, and operated independently. The service uses ssm-based springboot, and the services are coordinated through spring cloud. Technologies include:

MyBatis-Plus, SpringBoot, SpringMvc, SpringCloud (Eureka/Nacos, Zuul/Gateway, Config/Nacos, Feign, Hystrix/Sentinel, etc.), Redis, Fastdfs/Aicloud OSS, ElasticSearch, RabbitMQ, Velocity; Operation and maintenance : Aliyun server, Docker, Jenkins, Rancher, K8S, etc.

3.3. Project prototype

Insert picture description here

3.4. Development steps

The project is developed based on the front-end and back-end separation architecture. The front-end and back-end separation architecture generally includes the front-end and the server. Usually, multiple people collaborate and develop in parallel. The development steps are as follows:

1. Accept the project, establish the project
2. Requirements analysis (product manager), requirements document, outline design, function prototype diagram, sort out user needs, analyze business process
3. Project manager forms a team to develop PM ,SE,TM=PM+SE, project kick-off meeting, developer training (SE), project prototype construction (SE) development document
4. Development (development engineer)
a) Interface definition, defined according to requirement analysis Interface
b) Parallel development of server and front-end, develop server interface based on interface. postman test
c) The front-end develops the user interface and requests the server interface to complete business processing. EasyMock simulates data
d) Front-end and front-end integration tests The final front-end calls the server interface to complete the business.
5. Tester testing
6. Online operation and maintenance personnel
7. Operation and maintenance – leave one or two people
8. Develop other projects

4. Back-end project microservice prototype construction
4.1. Create Git warehouse (omitted)
4.1.1. Login code cloud creation warehouse
4.1.2. Local clone warehouse
4.1. 3. Create the project to the warehouse directory
4.1.4. Ignore the content that does not need to be submitted

4.2. Project structure construction

hrm-parent //Management jar: SpringBoot; SpringCloud, some public content
     hrm-support-parent //springcloud microservice support module
 hrm-eureka-server-1010
 hrm-zuul-server-1020
 hrm-config-server-1030
 hrm-basic-parent //basic module
     hrm-basic-util //Tools: AjaxResult, PageList
     hrm-basic-common //Common modules: BaseDoamin, BaseQuery
 hrm-system-parent //System Management Center
     hrm-system-common //system common code:��Copy tool class

Go to the courseware information reousrces/tools to find

2.hrm-system-commo imports mybatis-plus dependencies

Note: hrm-system-common only needs to import mybatis-plus-boot-starter, hrm-basic-util dependencies


     
         com.baomidou
         mybatis-plus-boot-starter
         2.2.0
     
    
     cn.itsource
     hrm-basic-common
     1.0-SNAPSHOT
     
 
 

hrm-system-server-1040 service adjustment

6.4.2. Import mybatis-plus jar

Modify hrm-system-server-1040 to import the following dependencies:


 com.baomidou
 mybatis-plus-boot-starter
 2.2.0
 

 
 mysql
 mysql-connector-java
 
        
             com.alibaba
             druid
             1.1.9
         
 
     cn.itsource.hrm
     hrm-system-common
     1.0-SNAPSHOT
 
 

6.4.3. Configure application.yml

spring:
   application:
     name: system-server #service name
   datasource:
     username: root
     password: 123456
     url: jdbc:mysql:///hrm-system
     driver-class-name: com.mysql.jdbc.Driver
     type: com.alibaba.druid.pool.DruidDataSource
 mybatis-plus: #integrate MyBatis-Plus
   mapper-locations: classpath:cn/itsource/hrm/mapper/*Mapper.xml
   #type-aliases-package: cn.itsource.hrm.domain, cn.itsource.hrm.query
 

6.4.4. MyBatis-Plus configuration class

import com.baomidou.mybatisplus.plugins.PaginationInterceptor;
 import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.transaction.annotation.EnableTransactionManagement;

 //Spring boot method
 @Configuration
 @MapperScan("cn.itsource.hrm.mapper") //mapper interface scan
 @EnableTransactionManagement //transaction management
 public class MybatisPlusConfig {

     /**
      * Pagination plugin
      */
     @Bean
     public PaginationInterceptor paginationInterceptor() {
         return new PaginationInterceptor();
     }
 }
 

6.4.5. Program entry class

package cn.itsource.hrm;

 import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;

 @SpringBootApplication
 @EnableEurekaClient
 public class SystemServerApplication2010{
     public static void main(String[] args) {
         SpringApplication. run(App. class, args);
     }
 }
 

6.4.6. Test - test after generating code

package cn.itsource.hrm;

 import cn.itsource.hrm.domain.User;
 import cn.itsource.hrm.service.IUserService;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.junit4.SpringRunner;

 @RunWith(SpringRunner. class)
 @SpringBootTest(classes = App. class)
 public class UserServiceTest {
     @Autowired
     private IUserService userService;

     @Test
     public void testGetAll() throws Exception{

         System.out.println(userService.selectById(1L));
 // userService. insert(new User());
 // userService. updateById(new User());
 // userService. deleteById(1L);
         for (User user : userService. selectList(null)) {
             System.out.println(user);
         }
     }
 }
 

6.5. System Management - Data Dictionary

The data dictionary is to use two tables to maintain some data items in the system that do not change frequently. The type of data items uses the data dictionary type table, and the detailed list of data items is maintained using the detailed table of the data dictionary. .

Use the code generator to generate the basic code, and then connect to the VUE front-end to do CRUD

Insert picture description hereInsert picture description here

6.5.1. Table design

Insert picture description here

Many-to-one design

6.5.2. Interface testing tool postman

Use postmain to test the data dictionary interface

7. System-server integration with Swagger
7.1. What is swagger
The interface document has been learned before, so there is not much introduction here, let's integrate directly
7.2. System integration with Swagger
7.2 .1. Import dependencies


     
         io.springfox
         springfox-swagger2
         2.9.2
     
     
     
         io.springfox
         springfox-swagger-ui
         2.9.2
     
 

7.2.2.Swagger configuration class

@Configuration
 @EnableSwagger2
 public class Swagger2 {
 
     @Bean
     public Docket createRestApi() {
         return new Docket(DocumentationType. SWAGGER_2)
                 .apiInfo(apiInfo())
                 .select()
                 // The package that exposes the service to the outside world is exposed in the form of a controller, so it is the package of the controller.
                 .apis(RequestHandlerSelectors.basePackage("cn.itsource.hrm.web.controller"))
                 .paths(PathSelectors. any())
                 .build();
     }


     private ApiInfo apiInfo() {
         return new ApiInfoBuilder()
                 .title("Platform service api")
                 .description("Platform Service Interface Document Description")
                 .Contact ("WhLE.CHEN", "", " [Email Protected] "))
                 .version("1.0")
                 .build();
     }

 }
 

Visit this project address: http://127.0.0.1:1040/swagger-ui.html

7.3. Gateway Configuration Swagger

It is not good to record the IP of each service every time for front-end development. It is expected that only the IP of the gateway will be ok, and it needs to be configured

7.3.1. Import dependencies

 
         
             io.springfox
             springfox-swagger2
             2.9.2
         
         
         
             io.springfox
             springfox-swagger-ui
             2.9.2
         
 

7.3.2.Swagger configuration class

package cn.itsource.hrm.config;

 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.context.annotation.Primary;
 import org.springframework.stereotype.Component;
 import springfox.documentation.builders.ApiInfoBuilder;
 import springfox.documentation.service.ApiInfo;
 import springfox.documentation.service.Contact;
 import springfox.documentation.spi.DocumentationType;
 import springfox.documentation.spring.web.plugins.Docket;
 import springfox.documentation.swagger.web.SwaggerResource;
 import springfox.documentation.swagger.web.SwaggerResourcesProvider;
 import springfox.documentation.swagger.web.UiConfiguration;
 import springfox.documentation.swagger2.annotations.EnableSwagger2;

 import java.util.ArrayList;
 import java.util.List;

 @Configuration
 @EnableSwagger2
 public class SwaggerConfig {

     @Bean
     public Docket createRestApi() {
         return new Docket(DocumentationType. SWAGGER_2)
                 .apiInfo(apiInfo());
     }

     private ApiInfo apiInfo() {
         return new ApiInfoBuilder()
                 .title("Source Code HR System")
                 .description("Source Code Human Resources Interface Document Description")
                 .termsOfServiceUrl("http://localhost:1020")
                 .contact ("What.chen", "", ""/CDN-CGI/L/Email-Protect "Class =" __ cf_email_ "data-cFEMAIL =" 4769405D5A465B5C4A4C074A47 "> [Email Protected] "))
                 .version("1.0")
                 .build();
     }
 }
 package cn.itsource.hrm.config;

 import org.springframework.context.annotation.Primary;
 import org.springframework.stereotype.Component;
 import springfox.documentation.swagger.web.SwaggerResource;
 import springfox.documentation.swagger.web.SwaggerResourcesProvider;

 import java.util.ArrayList;
 import java.util.List;

 @Component
 @Primary
 public class DocumentationConfig implements SwaggerResourcesProvider {
     @Override
     public List get() {
        List resources = new ArrayList();
        resources.add(swaggerResource("System Management", "/hrm/system/v2/api-docs", "2.0"));
        return resources;
     }

     private SwaggerResource swaggerResource(String name, String location, String version) {
         SwaggerResource swaggerResource = new SwaggerResource();
         swaggerResource.setName(name);
         swaggerResource.setLocation(location);
         swaggerResource.setSwaggerVersion(version);
         return swaggerResource;
     }
 }
 

Test: http://127.0.0.1:1020/swagger-ui.html

��Learned, there is not much introduction here, let’s integrate directly
7.2. System Integration Swagger
7.2.1. Import dependencies


     
         io.springfox
         springfox-swagger2
         2.9.2
     
     
     
         io.springfox
         springfox-swagger-ui
         2.9.2
     
 

7.2.2.Swagger configuration class

@Configuration
 @EnableSwagger2
 public class Swagger2 {
 
     @Bean
     public Docket createRestApi() {
         return new Docket(DocumentationType. SWAGGER_2)
                 .apiInfo(apiInfo())
                 .select()
                 // The package that exposes the service to the outside world is exposed in the form of a controller, so it is the package of the controller.
                 .apis(RequestHandlerSelectors.basePackage("cn.itsource.hrm.web.controller"))
                 .paths(PathSelectors. any())
                 .build();
     }


     private ApiInfo apiInfo() {
         return new ApiInfoBuilder()
                 .title("Platform service api")
                 .description("Platform Service Interface Document Description")
                 .Contact ("WhLE.CHEN", "", " [Email Protected] "))
                 .version("1.0")
                 .build();
     }

 }
 

Visit this project address: http://127.0.0.1:1040/swagger-ui.html

7.3. Gateway Configuration Swagger

It is not good to record the IP of each service every time for front-end development. It is expected that only the IP of the gateway will be ok, and it needs to be configured

7.3.1. Import dependencies

 
         
             io.springfox
             springfox-swagger2
             2.9.2
         
         
         
             io.springfox
             springfox-swagger-ui
             2.9.2
         
 

7.3.2.Swagger configuration class

package cn.itsource.hrm.config;

 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.context.annotation.Primary;
 import org.springframework.stereotype.Component;
 import springfox.documentation.builders.ApiInfoBuilder;
 import springfox.documentation.service.ApiInfo;
 import springfox.documentation.service.Contact;
 import springfox.documentation.spi.DocumentationType;
 import springfox.documentation.spring.web.plugins.Docket;
 import springfox.documentation.swagger.web.SwaggerResource;
 import springfox.documentation.swagger.web.SwaggerResourcesProvider;
 import springfox.documentation.swagger.web.UiConfiguration;
 import springfox.documentation.swagger2.annotations.EnableSwagger2;

 import java.util.ArrayList;
 import java.util.List;

 @Configuration
 @EnableSwagger2
 public class SwaggerConfig {

     @Bean
     public Docket createRestApi() {
         return new Docket(DocumentationType. SWAGGER_2)
                 .apiInfo(apiInfo());
     }

     private ApiInfo apiInfo() {
         return new ApiInfoBuilder()
                 .title("Source Code HR System")
                 .description("Source Code Human Resources Interface Document Description")
                 .termsOfServiceUrl("http://localhost:1020")
                 .contact ("What.chen", "", ""/CDN-CGI/L/Email-Protect "Class =" __ cf_email_ "data-cFEMAIL =" 4769405D5A465B5C4A4C074A47 "> [Email Protected] "))
                 .version("1.0")
                 .build();
     }
 }
 package cn.itsource.hrm.config;

 import org.springframework.context.annotation.Primary;
 import org.springframework.stereotype.Component;
 import springfox.documentation.swagger.web.SwaggerResource;
 import springfox.documentation.swagger.web.SwaggerResourcesProvider;

 import java.util.ArrayList;
 import java.util.List;

 @Component
 @Primary
 public class DocumentationConfig implements SwaggerResourcesProvider {
     @Override
     public List get() {
        List resources = new ArrayList();
        resources.add(swaggerResource("System Management", "/hrm/system/v2/api-docs", "2.0"));
        return resources;
     }

     private SwaggerResource swaggerResource(String name, String location, String version) {
         SwaggerResource swaggerResource = new SwaggerResource();
         swaggerResource.setName(name);
         swaggerResource.setLocation(location);
         swaggerResource.setSwaggerVersion(version);
         return swaggerResource;
     }
 }
 

Test: http://127.0.0.1:1020/swagger-ui.html

swaggerResource.setLocation(location);
swaggerResource.setSwaggerVersion(version);
return swaggerResource;
}
}

Test: http://127.0.0.1:1020/swagger-ui.html

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/spring-cloud-project-construction-process_tc-cloud_jjd_cxys-blog/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索