Spring-Anwendung-Eigenschaften-Profil mit war-Datei

Ich versuche, das Paket zu meinem Projekt in einer .war für einen tomcat-server-Bereitstellung. Ich brauche die Fähigkeit, meine application.properties ODER application-dev.properties ODER appliation-qa.properties ODER application-prod.properties. Läuft das Projekt mit dem eingebetteten servlet-ich bin in der Lage, geben Sie über die Befehlszeile, die ich verwenden wollen, aber das Projekt immer verwendet application.properties wenn ich es Verpacken wie ein .war.

Ich die folgenden Befehle verwenden, um mein Projekt vor Ort:

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

Ist und Sie diesen Befehl, um Paket zu meinem Projekt, obwohl Bambus für die Bereitstellung:

  • 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 = Logger.getLogger(Application.class);

        public static void main(String[] args) throws Exception {

            logger.info("Entering Application");
            SpringApplication.run(Application.class, args);
        }

        @Override
        protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
            return application.sources(Application.class);
        }

    }

pom.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>

        <groupId>org.springframework</groupId>
        <artifactId>wilson</artifactId>
        <version>3.0.1</version>

        <packaging>war</packaging>

        <properties>
            <java.version>1.8</java.version>
            <start-class>com.pandera.wilson.Application</start-class>
        </properties>

        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>1.3.6.RELEASE</version>
        </parent>

        <build>
            <finalName>wilson-services</finalName>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>

        <dependencies>

            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
                <exclusions>
                    <exclusion>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-logging</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.slf4j</groupId>
                        <artifactId>slf4j-log4j12</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>

            <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-log4j</artifactId>
            </dependency>

            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>

            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-thymeleaf</artifactId>
            </dependency>

            <dependency>
                <groupId>org.apache.httpcomponents</groupId>
                <artifactId>httpclient</artifactId>
                <version>4.5.2</version>
            </dependency>

            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-data-jpa</artifactId>
            </dependency>

            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-security</artifactId>
            </dependency>

            <dependency>
                <groupId>org.springframework.security.oauth</groupId>
                <artifactId>spring-security-oauth2</artifactId>
            </dependency>

            <dependency>
                <groupId>com.microsoft.sqlserver</groupId>
                <artifactId>sqljdbc4</artifactId>
                <version>4.0</version>
            </dependency>

            <dependency>
                <groupId>org.json</groupId>
                <artifactId>json</artifactId>
                <version>20160212</version>
            </dependency>

            <dependency>
                <groupId>commons-io</groupId>
                <artifactId>commons-io</artifactId>
                <version>2.4</version>
            </dependency>

            <dependency>
                <groupId>com.microsoft.azure</groupId>
                <artifactId>azure</artifactId>
                <version>1.0.0-beta2</version>
            </dependency>

        </dependencies>

        <repositories>
            <repository>
                <id>spring-releases</id>
                <url>https://repo.spring.io/libs-release</url>
            </repository>
        </repositories>

    </project>


EDIT 1:30 UHR 7-21-16

Habe ich noch folgende auf meiner pom.xml und versuchte die Verpackung mit mvn package -P PROD jedoch, wenn ich drücken Sie /about ich sehe immer noch, dass ich mit appliation.properties statt application-prod.properties.

<profiles>
    <profile>
        <id>QA</id>
        <properties>
            <spring.profiles.active>qa</spring.profiles.active>
        </properties>
    </profile>

    <profile>
        <id>DEV</id>
        <properties>
            <spring.profiles.active>dev</spring.profiles.active>
        </properties>
    </profile>

    <profile>
        <id>PROD</id>
        <properties>
            <spring.profiles.active>prod</spring.profiles.active>
        </properties>
    </profile>
</profiles>
haben, finden Sie die Lösung für dieses?
Die Aktualisierung meiner spring-boot-version behoben, die das für mich. Sie verändert die Art und Weise konfigurieren Sie die Anwendung für die externe servlet-Implementierungen und es das Problem behoben.

InformationsquelleAutor adenix | 2016-07-21

Schreibe einen Kommentar