標籤:uid htm exist info 參考 hue could not 重新命名 tom
POM
- 1.5
<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>1.5.10.RELEASE</version><relativePath/></parent>
- 2.0
<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.0.3.RELEASE</version><relativePath/></parent>
Spring Data
Spring Data的一些方法進行了重新命名:
- findOne(id) -> getOne(id)
- delete(id) -> deleteById(id)
- exists(id) -> existsById(id)
- findAll(ids) -> findAllById(ids)
配置
在升級時,可以在pom中增加spring-boot-properties-migrator,這樣在啟動時會提示需要更改的配置:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-properties-migrator</artifactId> <scope>runtime</scope></dependency>
其中改動較大的是security(The security auto-configuration is no longer customizable,A global security auto-configuration is now provided)和management部分。
- security
security開頭的配置及management.security均已到期,如以下的配置不再支援,需要調整到代碼中:
security:ignored: /api-docs,/swagger-resources/**,/swagger-ui.html**,/webjars/**
- management
management:security:enabled: falseport: 8090
修改為:
management:server:port: 8090
- datasource
datasource:initialize: false
修改為:
datasource:initialization-mode: never
如使用PostgreSQL,可能會報錯:Method org.postgresql.jdbc.PgConnection.createClob() is not yet implemented hibernate,需修改配置:
jpa: database-platform: org.hibernate.dialect.PostgreSQLDialect properties: hibernate: default_schema: test jdbc: lob: non_contextual_creation: true
更多需要調整的參數請看文末參考文檔。
Security
WebSecurityConfigurerAdapter
- security.ignored
@Overridepublic void configure(WebSecurity web) throws Exception {web.ignoring().antMatchers("/api-docs", "/swagger-resources/**", "/swagger-ui.html**", "/webjars/**");}
- AuthenticationManager
如在代碼中注入了AuthenticationManager,
@Autowiredprivate AuthenticationManager authenticationManager;
在啟動時會報錯:Field authenticationManager required a bean of type ‘org.springframework.security.authentication.AuthenticationManager‘ that could not be found.請在WebSecurityConfigurerAdapter中增加以下代碼:
@Bean@Overridepublic AuthenticationManager authenticationManagerBean() throws Exception {return super.authenticationManagerBean();}
Actuator
Actuator訪問路徑發生了變化,網址前部增加了單詞actuator([/actuator/health],[/actuator/info]),這可以在開機記錄中看到。
未完待續...
參考文檔
Spring Boot 2.0 Migration Guide
Spring Boot 2.0 Configuration Changelog
Spring Boot 2.0 新特性和發展方向
從Spring Boot 1.5升級到2.0