Springboot1.x upgrade to 2.x problem

The change of the output format of java time type after Jackson conversion

If no specific time format is specified, when returning a result with java time type via @ResponseBody, the java time type (java.util.Date, java.util.Calendar, java.sql.Date, java.sql .Timestamp, etc.) is returned as a timestamp (milliseconds of the current time), but in SpringBoot 2.0.2, the return format is formatted: yyyy-mm-ddTHH:mi:ss.
If you want to continue to return data in timestamp format, you only need to add the following configuration to the properties configuration file:

spring.jackson.serialization.write-dates-as-timestamps=true

Note: The impact of SpringBoot 2.0.2 on java time format has no effect on the new java.time.LocalDateTime added in java8. When spring.jackson.serialization.write-dates-as-timestamps=true is set, java.time. LocalDateTime will be converted into an array like [2018,5,31,17,58,35] instead of milliseconds.

Context-path configuration modification

SpringBoot 1.5.9 configures context-path in the properties file as follows:

server.context-path = XXX

In SpringBoot 2.0.2, its configuration method has become

server.servlet.context-path = XXX

@ConfigurationProperties configuration restrictions

In SpringBoot, @ConfigurationProperties can be used to transform an entity class into a configurable class (you can directly configure the value of the corresponding parameter in the properties file, and it will automatically prompt if you use the IDE). When setting the prefix attribute of @ConfigurationProperties in SpringBoot 1.5.9, there is no problem using camel case naming (such as eclipseLink), but an error will be reported when Spring Boot 2.x starts:

InvalidConfigurationPropertyNameException: Configuration property name '********' is not valid.

There will be no problems when using eclipse-link.

Multiple data source configuration issues

If multiple data sources are configured in Spring Boot 2.x, there is one configuration that needs attention: spring.datasource.url! This configuration may be problematic and needs to be set to spring.datasource.jdbc -url!

After Spring Boot 2.1.x version, beans with the same name are not supported by default

Need to increase the configuration spring.main.allow-bean-definition-overriding=true. But this is a very dangerous configuration. Bean override is enabled. If you define a duplicate bean, you don't know it. This may cause you to be unsure which bean is causing business problems. So it is not recommended to open.

Another solution is to refer to: Support Multiple Clients Using The Same Service

Use the contextId configuration in FeignClient:

@FeignClient(value = "service-provider", contextId = "UserService")
public interface UserService {
}
@FeignClient(value = "service-provider", contextId = "RetailerService")
public interface RetailerService {
}

Guess you like

Origin blog.csdn.net/chen_cxl/article/details/108869455