升級到spring boot 2.x後,發現了好多坑,現記錄下來。spring
一、pom文件依賴的變化ide
1.x中,依賴是這樣的:spa
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka</artifactId> </dependency>
2.x,依賴是這樣的:.net
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> </dependency>
猜想是將eureka移到netflix包中了。目前發現依賴變化的有:eureka、feign、hystrixcode
二、Repository取消了findOne(id)方法csrf
1.x中,有findOne(id)方法server
User user = userRepository.findOne(Long id)
2.x中,取消了findOne(id)方法,能夠使用getOne(id)或者findById(id)blog
User user = userRepository.getOne(id); User user = userRepository.findById(id).get();
三、使用eureka註冊中心時,eureka客戶端註冊不了,報錯以下:get
com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
緣由是升級後,security默認啓用了csrf檢驗,要在eurekaServer端配置security的csrf檢驗爲false。須要增長的配置類以下:it
@EnableWebSecurity public class WebSecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http.csrf().disable(); super.configure(http); } }