Since 2 series of spring boot was released, it is a memo when upgrading because it is a big deal
The migration guide is officially available, so follow this procedure. Spring Boot 2.0 Migration Guide Also, this article was very helpful. Memorandum of understanding when Spring Boot 1.5.10 → Spring Boot 2.0.0
build.gradle as described in [Before You Start](https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.0-Migration-Guide#before-you-start) Add the following to
.
build.gradle
runtime("org.springframework.boot:spring-boot-properties-migrator")
This will warn you of changes in the specifications of ʻapplication.yml`.
Dependency Management plugin as described in [https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.0-Migration-Guide#dependency-management) To add.
build.gradle
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management' // <-- add this to your build.gradle
Since spring.batch.initializer.enabled
was changed to spring.batch.initialize-schema
, change it here.
Since it does not initialize, set never
.
Initialize a Spring Batch Database
application.yml
spring:
batch:
initializer:
enabled: false
application.yml
spring:
batch:
initialize-schema: never
What I set in camel case on application.yml was an error. Even if it's a kebab case. So I will make it a kebab case.
application.yml
spring:
datasource:
hogeHoge:
driverClassName: com.mysql.jdbc.Driver
application.yml
spring:
datasource:
hoge-hoge:
driver-class-name: com.mysql.jdbc.Driver
Previously, jar files were generated with bootRepackage
for package generation, but this seems to be abolished.
Replaced by bootJar
and bootWar
. However, due to the setting of the matter, bootJar
is set to ʻenabled = false`.
build.gradle
mainClassName = 'jp.co.hoge.fuga.App'
bootRepackage {
executable = true
}
jar {
manifest {
attributes 'GitHub-Branch-Name' : branchname
attributes 'GitHub-Commit-Hash' : commithash
}
}
build.gradle
ext.mainClass = 'jp.co.hoge.fuga.App'
bootJar {
enabled = false
}
jar {
enabled = true
manifest {
attributes 'GitHub-Branch-Name' : branchname
attributes 'GitHub-Commit-Hash' : commithash
}
}
Originally I used gradlew was 4.6, but I will give it to the latest 4.7.
build.gradle
task wrapper(type: Wrapper) {
gradleVersion = "4.7"
}
I used to use tomcat connection pool before HikariCP has become the default, so change it there.
DataSourceConfiguration.java
@Data
@Component
@ConfigurationProperties(prefix = "spring.datasource.hoge")
public class DataSourceConfiguration {
private String driverClassName;
private String url;
private String username;
private String password;
private Boolean testOnBorrow;
private String validationQuery;
public DataSource dataSource() {
DataSource ds = new org.apache.tomcat.jdbc.pool.DataSource();
ds.setDriverClassName(driverClassName);
ds.setUrl(url);
ds.setUsername(username);
ds.setPassword(password);
ds.setTestOnBorrow(testOnBorrow);
ds.setValidationQuery(validationQuery);
return ds;
}
}
DataSourceConfiguration.java
@Data
@Component
@ConfigurationProperties(prefix = "spring.datasource.hoge")
public class DataSourceConfiguration {
private String driverClassName;
private String url;
private String username;
private String password;
private Integer maxPoolSize;
private String validationQuery;
public HikariDataSource dataSource() {
HikariDataSource ds = new HikariDataSource();
ds.setDriverClassName(driverClassName);
ds.setJdbcUrl(url);
ds.setUsername(username);
ds.setPassword(password);
ds.setConnectionInitSql(validationQuery);
ds.setMaximumPoolSize(maxPoolSize);
return ds;
}
}
You should also set query timeout etc, but I didn't set it this time because there is sql from batch that keeps running for a long time.
Due to spring5, WebMvcConfigurerAdapter
has been deprecated.
Since it says that you can use WebMvcConfigurer
, change it there.
I think it's because I started using the default method.
WebMvcConfig.java
@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {
//Abbreviation
}
WebMvcConfig.java
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
//Abbreviation
}
Originally deprecated, it has been deprecated and needs to be changed.
PasswordEncoderConfig.java
@Bean
public PasswordEncoder md5PasswordEncoder() {
return new Md5PasswordEncoder();
}
PasswordEncoderConfig.java
@Bean
public PasswordEncoder md5PasswordEncoder() {
return new MessageDigestPasswordEncoder("MD5");
}
I would like to stop using MD5 itself, but it is not recommended because it is quite difficult for long-lasting projects, but I will avoid it once.
I will use it because it was added from spring security 5.
It seems that it delegates the processing to the appropriate PasswordEncoder for each password hashing algorithm.
There was a class that sets it by default, so use PasswordEncoderFactories
to generate it.
By default it returns bcrypt.
PasswordEncoderConfig.java
@Bean
public PasswordEncoder delegatingPasswordEncoder() {
return PasswordEncoderFactories.createDelegatingPasswordEncoder();
}
ʻOrg.hibernate.validator.constraints.NotBlankhas been deprecated and will be changed. Since
javax.validation.constraints.NotBlank` is implemented with the same class name, it was OK to replace only the import part at once.
With this kind of response, it works fine. end
Recommended Posts