zoukankan      html  css  js  c++  java
  • 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下执行就可以了。

    
    
  • 相关阅读:
    laravel 使用 php artisan make:model到指定目录(controller同理)
    Mysql常见的优化策略
    laravel路由别名
    laravel whereNotIn where子查詢
    phpstorm界面不停的indexing,不停的闪烁
    Linux下Redis开机自启(Centos6)
    数据结构常用算法
    困惑的前置操作与后置操作
    SSH框架整合中Hibernate实现Dao层常用结构
    过滤器与拦截器区别
  • 原文地址:https://www.cnblogs.com/yg_zhang/p/9802025.html
Copyright © 2011-2022 走看看