标签:app resource turn 启动 info public listen path imp
springboot 一般使用jar 的方式运行,我们需要将程序放到tomcat环境下运行。
步骤如下:
1.修改pom文件。
排除内置的tomcat
<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> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </exclusion> </exclusions> </dependency>
修改打包方式
<packaging>war</packaging>
jar的方式改成 war打包。
2.修改启动代码
@SpringBootApplication @ImportResource("classpath:transaction.xml") @MapperScan({"com.neo.dao"}) public class DemoApplication extends SpringBootServletInitializer { public static void main(String[] args) { SpringApplication app=new SpringApplication(DemoApplication.class); app.addListeners(new ApplicationStartedEventListener()); app.addListeners(new ApplicationStartingEventListener()); app.addListeners(new ApplicationStartedEventListener2()); app.run(args); } @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(DemoApplication.class); } }
增加代码
@Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(DemoApplication.class); }
3.进行打包
将打包后的代码放到tomcat下执行就可以了。
标签:app resource turn 启动 info public listen path imp
原文地址:https://www.cnblogs.com/yg_zhang/p/9802025.html