最近將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