使用外部tomcat部署时,为排除springboot内置的tomcat,修改pom.xml文件,增加
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <!--排除内置容器,排除内置容器导出成war包可以让外部容器运行spring-boot项目--> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </exclusion> </exclusions> </dependency>
修改启动类Application.java,继承SpringBootServletInitializer,改写configure方法,修改启动方式
@EnableEurekaServer @SpringBootApplication public class EurekaServerApplication extends SpringBootServletInitializer{ @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { return builder.sources(EurekaServerApplication.class); } public static void main(String[] args) { //SpringApplication.run(EurekaServerApplication.class, args); new SpringApplicationBuilder(EurekaServerApplication.class).web(true).run(args); } }