码迷,mamicode.com
首页 > 编程语言 > 详细

spring-boot分环境打包为war包

时间:2019-01-22 20:13:23      阅读:130      评论:0      收藏:0      [点我收藏+]

标签:prot   nbu   gap   pac   charset   timeout   clu   har   字符   

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即可

spring-boot分环境打包为war包

标签:prot   nbu   gap   pac   charset   timeout   clu   har   字符   

原文地址:https://www.cnblogs.com/qdwyg2013/p/10305768.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!