springboot 程序发布到tomcat运行


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下执行就可以了。


					


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM