zoukankan      html  css  js  c++  java
  • spring-boot分环境打包为war包

    1.启动类修改

    @EnableSwagger2
    @SpringBootApplication
    public class CustWebAcApplication extends SpringBootServletInitializer {
    
        public static void main(String[] args) {
            SpringApplication.run(CustWebAcApplication.class, args);
        }
    
        @Override
        protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
            return application.sources(CustWebAcApplication.class);
        }
    
        @Bean
        public RestTemplate restTemplate() {
    
    //        SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
    //        // 设置超时 10s
    //        requestFactory.setConnectTimeout(10000);
    //        requestFactory.setReadTimeout(10000);
    
            RestTemplate restTemplate = new RestTemplate();
    
            // 使用utf-8字符集
            restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(Charset.forName("UTF-8")));
    
            return restTemplate;
        }
    
    }

    2.pom配置

        <!-- 多环境打包 start -->
        <profiles>
            <!-- 开发环境配置 -->
            <profile>
                <id>dev</id>
                <properties>
                    <profiles.active>dev</profiles.active>
                </properties>
                <activation>
                    <activeByDefault>true</activeByDefault>
                </activation>
            </profile>
            <!-- 测试环境配置 -->
            <profile>
                <id>test</id>
                <properties>
                    <profiles.active>test</profiles.active>
                </properties>
            </profile>
            <!-- 正式环境 -->
            <profile>
                <id>online</id>
                <properties>
                    <profiles.active>online</profiles.active>
                </properties>
            </profile>
        </profiles>
        <!-- 多环境打包 end -->
    
        <build>
            <resources>
                <resource>
                    <directory>src/main/java</directory>
                    <includes>
                        <include>**/*.class</include>
                        <include>**/*.xml</include>
                        <include>**/*.properties</include>
                    </includes>
                </resource>
                <resource>
                    <directory>src/main/resources</directory>
                    <includes>
                        <include>*.xml</include>
                        <include>*.properties</include>
                    </includes>
                    <filtering>true</filtering>
                </resource>
                <resource>
                    <directory>src/main/resources/conf/${profiles.active}</directory>
                </resource>
            </resources>
            <plugins>
                <plugin>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>2.6</version>
                    <configuration>
                        <!--如果想在没有web.xml文件的情况下构建WAR,请设置为false. -->
                        <failOnMissingWebXml>false</failOnMissingWebXml>
                    </configuration>
                </plugin>
            </plugins>
        </build>

    3.打包命令

    mvn clean package -Dmaven.test.skip=true -Ptest

    4.启动

    将war包放到tomcat的webapps下,启动tomcat即可

  • 相关阅读:
    去掉百度地图左下角文字和图标。
    使用CMake,且在GCC编译时指定相对源代码路径选项BUG的问题
    一键杀死某些指定进程的脚本
    KMS使用CLion作为IDE来调试
    ubuntu 18.04下安装编译的KMS,依赖库
    ubuntu 18.04下编译最新版本的KMS
    configure.ac中AC_CHECK_LIB的问题
    C/C++下__FILE__参数过长的问题解决办法
    Linux 下 UltraEdit 版本 破解 30 天试用限制
    ubuntu下配置ProFtpd服务使用sqlite3作为后端用户认证
  • 原文地址:https://www.cnblogs.com/gangzi2013/p/10305768.html
Copyright © 2011-2022 走看看