升级到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); } }