JeecgBoot since open source has been asked the most is the microservice version when? Microservices are a trend, especially with the interest in the mid-stage concept, every company is in urgent need of microservices. According to your needs, we launched the Version of JeECG-Cloud using SpringCloud Alibaba system!! However, maintaining two sets of code at the same time is too expensive for our team. In order to reduce the maintenance cost and give users an intelligent choice, we launched a new version of JeecgBoot 2.3. We specially created a free switching mechanism between monomer and micro-service, and a set of code can easily switch between monomer and micro-service.

The current new version of JeecgBoot 2.3 platform provides system, Demo and other modules by default, which can quickly start each module separately as a micro-service application and switch to cloud. The project adopts SpringCloud Alibaba technology stack as follows:

  • Service registration: NACOS
  • Configuration center: nacos-config
  • Reason Gateway: gateway
  • Interservice invocation: OpenFeign
  • Fuses and downgrades: Sentinel
  • Service monitoring: Spring Boot Admin

Video Tutorial: >> Unit upgrade microservice video tutorial

The following is the single rapid upgrade microservice scheme:

Upgrade the system module to an independent service

1. Delete the dependencies of other modules from the POM file of the system project and retain only local-API

2. The System project starts as a microservice and needs to add microservice dependencies
<! -- nacos --> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> </dependency> <! --> <dependency> <groupId>com.alibaba. Cloud </groupId> <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId> </dependency> <! <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId> </dependency>Copy the code
3. Create bootstrap.yml in the resource folder as follows:
spring:
  profiles:
    active: dev
  application:
    name: jeecg-system
  cloud:
    nacos:
      discovery:
        server-addr: 127.0.0.1:8848
feign:
  sentinel:
    enabled: true
Copy the code
4. Modify the dev configuration file and delete the two configurations in the screenshot

5. Add a comment to the startup class:@EnableDiscoveryClient

2. Upgrade other modules to independent services (such as Demo module)

Take demo as an example:

1. Modify the POM to change local-API to cloud-api

<dependency>
   <groupId>org.jeecgframework.boot</groupId>
   <artifactId>jeecg-system-cloud-api</artifactId>
</dependency>
Copy the code
2. Add the configuration file bootstrap.yml(if it does not have the following content) :
Spring: Profiles: active: dev Application: name: Jeecg-demo Cloud: nacos: Discovery: server-addr: 127.0.0.1:8848 feign: sentinel: enabled: trueCopy the code
3. Add the application-dev.yml configuration file (if it does not exist). The content can be directly copied to the file with the same name in the system

4. Create a startup class in org.jeecg (if not available)
package org.jeecg;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;

import java.net.UnknownHostException;

@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
public class JeecgDemoApplication {

    public static void main(String[] args) throws UnknownHostException {
        SpringApplication.run(JeecgDemoApplication.class, args);
    }
}
Copy the code

When the above steps are complete, NACOS is started to run the startup class test microservice for each module.

Start Nacos

Microservices integration Nacos service registry discover docke installation Nacos documentation: https://nacos.io/zh-cn/docs/quick-start-docker.htmlCopy the code
1. Start nacOS and accesslocalhost:8848/nacosThe account password is nacOS. Check the list of services

2. Start System and Demo and view the service list

4. Start the Gateway

Start the class: org. Jeecg. JeecgGatewayApplication



View online interface documentation:http://127.0.0.1:9999/doc.html

Five, start the front end

_CONFIG[‘domianURL’] = ‘window._CONFIG[‘domianURL’] =’http://127.0.0.1:9999 is the port numberPort 9999 must be the same as the gateway port

Q&A
1. An error occurs during gateway startup. You need to manually compile the Gateway project

2. The demo project startup Error javax.mail. Mail. AuthenticationFailedException: 535 Error: authentication failed
Note: Some configurations need to be modified for the interaction between the front and back ends. 1. Each service yML configuration has a property 'context-path: / jeECG-boot', which needs to be changed to '/' or deleted directly after sertization. 'window._CONFIG['domianURL'] = 'http://127.0.0.1:9999', where port '9999' is the same as gateway port 3. Cross-domain Settings, which can be ignored, Document for record # cross-domain problem comment out the two classes of cross-domain set org/jeecg/config/shiro/filters/JwtFilter. Java: 65 org/jeecg/config/WebMvcConfiguration Java: 49Copy the code