小编ade*_*nix的帖子

Spring应用程序属性配置文件与war文件

我正在尝试将我的项目打包到.war一个tomcat服务器部署中.我需要用我的能力application.properties OR application-dev.properties appliation-qa.properties OR application-prod.properties.使用嵌入的servlet运行项目我可以通过命令行指定我想要使用的项目,但是,application.properties当我将它打包为一个项目时,项目总是使用.war.

我使用以下命令在本地运行我的项目:

  1. mvn spring-boot:run
  2. mvn spring-boot:run -Drun.arguments="--spring.profiles.active=dev"

这个命令将我的项目打包成竹子进行部署:

  • mvn package -Dspring.profiles.active=qa


Application.java

    package com.pandera.wilson;

    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.boot.builder.SpringApplicationBuilder;
    import org.springframework.boot.context.web.SpringBootServletInitializer;
    import org.springframework.context.annotation.ComponentScan;
    import org.springframework.core.env.AbstractEnvironment;
    import org.springframework.scheduling.annotation.EnableAsync;
    import org.springframework.scheduling.annotation.EnableScheduling;

    import javax.servlet.ServletContext;
    import javax.servlet.ServletException;

    import org.apache.log4j.Logger;

    /**
     * @author Gaurav Kataria
     * @author Austin Nicholas
     * @category Application
     */

    @SpringBootApplication
    @ComponentScan(basePackages = { "com.pandera.wilson" })
    @EnableAsync
    public class Application extends SpringBootServletInitializer {

        static final Logger logger …
Run Code Online (Sandbox Code Playgroud)

java tomcat war maven spring-boot

8
推荐指数
3
解决办法
1万
查看次数

标签 统计

java ×1

maven ×1

spring-boot ×1

tomcat ×1

war ×1