SpringBoot项目添加到Eclipse的Tomcat中运行

时间:2024-04-12 18:49:10
1、首先在Maven依赖中添加依赖;

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
    <scope>provided</scope>
</dependency>

注:SpringBoot默认是内嵌tomcat,现在因为要放到独立的tomcat中运行,原内嵌的tomcat就不需要了,所以在Maven中添加spring-boot-starter-tomcat并设置为provided,这样打包的时候会把这个依赖排除;

3、SpringBoot 入口类【Application,需要继承【SpringBootServletInitializer】,并重写【configure】方法;
@SpringBootApplication(scanBasePackages={"com.andy"})
public class Application extends SpringBootServletInitializer{
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(Application.class);
}
}

4、然后把项目添加到tomcat中运行即可。

SpringBoot项目添加到Eclipse的Tomcat中运行

SpringBoot项目添加到Eclipse的Tomcat中运行