最近将springboot1.5升级到2.0版本。在升级过程当中总共须要修改3处,pom.xml、application.yml和ApiApplication.java三个文件。java
<!--注释1.5版本,增长2.0版本--> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <!--<version>1.5.10.RELEASE</version>--> <version>2.0.0.RELEASE</version> </parent>
<!--druid 1.8版本之后才支持springboot2.0。我改为最新的版本:1.1.9,旧版本为:1.1.5--> <properties> <!--<druid.version>1.1.5</druid.version>--> <druid.version>1.1.9</druid.version> </properties> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid-spring-boot-starter</artifactId> <version>${druid.version}</version> </dependency>
<!--修改前(1.5版本)--> server: context-path: /api <!--修改后(2.0版本)--> server: servlet: context-path: /api
<!--修改前(1.5版本)--> spring: http: multipart: max-file-size: 100MB max-request-size: 100MB enabled: true <!--修改后(2.0版本)--> server: servlet: multipart: max-file-size: 100MB max-request-size: 100MB enabled: true
<!--主要修改SpringBootServletInitializer类引用路径。--> <!--修改前(1.5版本)--> import org.springframework.boot.web.support.SpringBootServletInitializer; @SpringBootApplication public class ApiApplication extends SpringBootServletInitializer { public static void main(String[] args) { SpringApplication.run(ApiApplication.class, args); } @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(ApiApplication.class); } } <!--修改后(2.0版本)--> package com.mybitauto; import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; @SpringBootApplication public class ApiApplication extends SpringBootServletInitializer { public static void main(String[] args) { SpringApplication.run(ApiApplication.class, args); } @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(ApiApplication.class); } }
在此次升级中,能够看出在2.0版本中将更多的节点升级在servlet容器配置节点下。springboot也愈来愈规范化了。在配置上springboot愈来愈简化。但在简化的同时也能够让咱们了解到这些配置背后对应的框架业务逻辑。也有利于入门级的更好的了解springboot架构设计的背后的逻辑。web