This article is a simple record of some of the pits that individuals have encountered while doing the spring boot micro-service transformation.
One, spring boot hot deployment
Spring boot hot deployment is available in two ways:
To add springloaded dependencies in Spring-boot-maven-plugin, the POM is as follows:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactid>spring-boot-maven-plugin </artifactId>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>springloaded</artifactId>
<version>1.2.4.RELEASE</version>
</dependency>
</dependencies>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<classifier>exec</classifier>
</configuration>
</execution>
</executions>
</plugin>
Pit: Add dependencies after hot deployment does not work
Solution:
1, set idea allows the application to automatically compile, a total of two settings
2. The spring boot app must be started using spring Boot-run
3, Spring Boot-run start, MAVEN warehouse address can not have spaces, otherwise it will lead to start error, can not find springloaded jar package.
Using Dev_tools:
Add a jar dependency, add fork parameter in Spring-boot-maven-plugin, this kind of support is more comprehensive to the hot deployment, but will cause the application to restart frequently after the modification, the person finally uses this kind of way
Second, spring boot add mybatis support
1. Using a custom MyBatis configuration file
In the spring boot configuration, add:
MyBatis
Mapper-locations:classpath:mapper/*.xml
Config-location:classpath:mybatisconfiguration.xml
Pit: When using MyBatis when customizing the paging plugin, error: Method not found Statementhandler.prepare
Solution: MyBatis 3.4 Version Statementhandler.prepare added an int type parameter, modified as follows:
@Intercepts ({@Signature (type =statementhandler.class, method = "Prepare", args ={connection.class, integer.class})
Pit: Spring boot add mybatis after start times wrong: required a single bean, but 2 were found
Solution: Specify Annotationclass in the @mapperscan annotation of the Spring boot class:
@MapperScan (value = "Com.asiainfo.microservice", Annotationclass = Org.springframework.stereotype.Repository.class)
Of course, the corresponding DAO interface needs to add @repository annotations
Third, spring boot service dependency
Pit: The class in the dependent jar package could not be found
Solution: Spring boot uses spring-boot-maven-plugin to make a jar package that is not directly available to third-party dependencies and needs to modify the configuration to hit a single, dependent jar package, such as a dependency B,
Add in B:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>api-jar</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>api</classifier>
</configuration>
</execution>
</executions>
</plugin>
Add in a:
<dependency>
<groupId>XXXX</groupId>
<artifactId>XXXX</artifactId>
<version>1.0-SNAPSHOT</version>
<classifier>api</classifier>
</dependency>
Iv. Spring Boot Auto Configuration
Pit: Configuration not found
Description: A dependent third party jar Package B contains mybatis, and spring boot automatically finds the DataSource configuration when a is started, and the error is not found.
Solution: Note dependency delivery, disabling irrelevant dependencies
V. Spring Boot Scan Range
The startup class in spring boot can specify the scan range through the @componentscan annotation, and the default scan starts the package and its child packages, if not added.
If a dependent third-party jar has a class that needs to be scanned, it needs to be specified in @componentscan.
6. Resttemplate Service Call
Using Resttemplate to make calls between MicroServices, get method stitching URL parameters, if there are JSON format parameters, will error URL illegal,
The URL legal character does not contain {,}, "and cannot be passed directly with the Get method for JSON parameters. Escaping a special character will cause Jackson to parse the JSON
An error occurred for object, the problem is not resolved, and is currently used to not pass JSON format parameters in the Get method.