1、修改启动类
修改前:
package com.rsi.rc.ae;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.cache.annotation.EnableCaching;import org.springframework.cloud.client.discovery.EnableDiscoveryClient;import org.springframework.cloud.openfeign.EnableFeignClients;import org.springframework.context.annotation.ComponentScan;import org.springframework.scheduling.annotation.EnableAsync;import org.springframework.scheduling.annotation.EnableScheduling;import springfox.documentation.swagger2.annotations.EnableSwagger2;@SpringBootApplication@EnableSwagger2@EnableDiscoveryClient@EnableCaching // 启用数据缓存@ComponentScan(value = "com.rsi.rc")@EnableFeignClients("com.rsi.rc")@EnableAsync@EnableSchedulingpublic class App { public static void main(String[] args) throws InterruptedException { SpringApplication.run(App.class, args); }}
修改后:
package com.rsi.rc.ae;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;import org.springframework.cache.annotation.EnableCaching;import org.springframework.cloud.client.discovery.EnableDiscoveryClient;import org.springframework.cloud.openfeign.EnableFeignClients;import org.springframework.context.annotation.ComponentScan;import org.springframework.scheduling.annotation.EnableAsync;import org.springframework.scheduling.annotation.EnableScheduling;import springfox.documentation.swagger2.annotations.EnableSwagger2;@SpringBootApplication@EnableSwagger2@EnableDiscoveryClient@EnableCaching // 启用数据缓存@ComponentScan(value = "com.rsi.rc")@EnableFeignClients("com.rsi.rc")@EnableAsync@EnableSchedulingpublic class App extends SpringBootServletInitializer { public static void main(String[] args) throws InterruptedException { SpringApplication.run(App.class, args); } @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { return builder.sources(App.class); }}
2、修改pom文件
war
org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-tomcat
org.springframework.boot spring-boot-starter-tomcat provided
3、注意的地方:
1、application.xml 配置文件
配置的
server.port
server.servlet.context-path
将会失效 因为这些是配置内部tomcat的
2、还有tomcat访问是路径是带项目名的,这个和jar的方式是不一样的