项目升级springboot2.0注意事项

一.pring boot 2.0以后, springboot jpa findById 返回类型变化

@NoRepositoryBean
public interface CrudRepository<T, ID> extends Repository<T, ID> {
    <S extends T> S save(S var1);

    <S extends T> Iterable<S> saveAll(Iterable<S> var1);

    Optional<T> findById(ID var1);

源码中返回的是Optional 类型。那么这个时候该如何获得T 类型呢
只需要get()即可
就是findById(Id).get() 即返回T类型

二 .自定义springmvc配置需要实现WebMvcConfigurer或继承WebMvcConfigurationSupport(会使springboot对springmvc的自动配置失效)

对应的依赖包需升级到相应的高版本

springboot热部署:添加依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
<scope>true</scope>
</dependency>

<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<!--是否启动热部署-->
<fork>true</fork>
</configuration>
</plugin>


并且勾选编辑器的自动编译

三.Spring Security 报There is no PasswordEncoder mapped for the id "null",spring security 版本在5.0后就要加个PasswordEncoder了
//inMemoryAuthentication 从内存中获取  
auth.inMemoryAuthentication().passwordEncoder(new BCryptPasswordEncoder()).withUser("user1").password(new BCryptPasswordEncoder().encode("123456")).roles("USER");
详情:https://blog.csdn.net/canon_in_d_major/article/details/79675033

四.【spring Boot】spring boot1.5以上版本@ConfigurationProperties取消location注解后的替代方案
详情:https://www.cnblogs.com/sxdcgaq8080/p/7651697.html
@ConfigurationProperties(
prefix = "paymentcard",
ignoreUnknownFields = false
)

注意:1.5后自定义资源配置文件不支持大写,驼峰命名,prefix值必须小写,否则报错

五.Spring Boot 2.0 去掉了findOne()方法。
盛世岂埋凌云气,年少无为就努力
原文地址:https://www.cnblogs.com/guangchuantang/p/10833363.html