占坑
springboot1.5.9升级springboot2.0.5
此升级只适应于参考(本公司暂时正常运行)
原文链接
官网翻译
spring-cloud 组件
-
springboot 版本
<version>2.0.5.RELEASE</version>
-
springcloud 版本
<version>Finchley.RELEASE</version>
-
eureka-server 替换
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> </dependency>
-
eureka-client 替换 2.0.X guava scope 为runtime 项目引用不到
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency> <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> </dependency>
-
feign 替换
NOTIVE
这个包下注解及类路径更换需要批量替换路径问题
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
版本替换
<properties>
<xstream.version>1.4.10</xstream.version>
<validation-api.version>2.0.1.Final</validation-api.version>
<stream-kafka.version>2.0.3.RELEASE</stream-kafka.version>
<wxcep-cache.version>2.0.0-SNAPSHOT</wxcep-cache.version>
</properties>
spring-cloud-stream-kafka
配置文件
#security
spring:
# 安全认证的配置
security:
basic:
enabled: true
user:
name: username # 用户名
password: passwd # 用户密码
#server
server:
servlet:
context-path: /spring-web
#redis
spring:
redis:
host: 192.168.6.110
port: 6385
password: root
jedis:
pool.max-idle: 8
pool.min-idle: 1
pool.max-active: 8
pool.max-wait: -1
@ConfigurationProperties
不支持下划线
@ConfigurationProperties(prefix = "spring.dsslave", ignoreInvalidFields = true, ignoreUnknownFields= false)
public class SlaveDruidProperties{}
排除pom
启动后退出无日志日志输出
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
低版本method不存在导致启动task报错
<exclusions>
<exclusion>
<artifactId>netty-all</artifactId>
<groupId>io.netty</groupId>
</exclusion>
</exclusions>
spring-data-redis
{
@Bean
@ConditionalOnMissingBean
public CacheManager cacheManager(RedisConnectionFactory factory) {
RedisCacheManager cacheManager = RedisCacheManager.create(factory);
log.info("cacheManager initialization successful......");
return cacheManager;
}
}
Security
eureka server中配置了security注意事项 否则出现eureka client注册不上服务
@EnableWebSecurity
static class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable();
super.configure(http);
}
}
WebMvcConfigurerAdapter
WebMvcConfigurerAdapter废弃 转换器替换去除MappingJackson2HttpMessageConverter MappingJackson2HttpMessageConverter 不支持@RequestBody JSON object 转换为String springboot2.0.X加载转换器顺序问题(优先加载了默认转换器)springboot1.5.9把自定义转换器加载在首位
/**
* MVC转换器
*/
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
// 去掉jackson,添加fastjson
List<HttpMessageConverter<?>> filterconverters = converters.stream().filter(covert -> !(covert instanceof MappingJackson2HttpMessageConverter)).collect(Collectors.toList());
filterconverters.add(createFastJsonConverter());
converters.clear();
converters.addAll(filterconverters);
}
Exception
不返回exception 导致异常解析失败
(不可使用@ControllerAdvice与@ExceptionHandler处理异常,但@ControllerAdvice与@ExceptionHandler 只能处理controller中的异常)
ErrorMvcAutoConfiguration
BasicErrorController
org.springframework.boot.autoconfigure.web.BasicErrorController#error
org.springframework.web.servlet.HandlerExceptionResolver
自定义异常
@Bean
public ErrorAttributes errorAttributes(){
return new CustomErrorAttributes();
}
public class CustomErrorAttributes extends DefaultErrorAttributes {
public CustomErrorAttributes() {
super();
}
@Override
public Map<String, Object> getErrorAttributes(WebRequest webRequest, boolean includeStackTrace) {
Map<String, Object> errorAttributes = super.getErrorAttributes(webRequest, includeStackTrace);
Throwable error = getError(webRequest);
if(null == error){
return errorAttributes;
}
errorAttributes.put("exception", error.getClass().getName());
return errorAttributes;
}
}
1.5.9
返回exception
org.springframework.boot.web.servlet.error.DefaultErrorAttributes#getErrorAttributes
tomcat 版本支持
外部容器启动
springboot2.0最低支持8.5
tomcat 8.0.36 不兼容
org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory#addDefaultServlet
context.addServletMappingDecoded("/", "default");
tomcat 8.0.36 org.apache.catalina.Context java.lang.NoSuchMethodError
来源:oschina
链接:https://my.oschina.net/u/3876288/blog/4307863