简体   繁体   English

在STS中使用Maven和配置文件启动SPRING BOOT可部署战争文件

[英]SPRING BOOT deployable war file with maven and profiles in STS

I'm trying to make my spring boot app ready for easy packaging war using profiles (dev, prod ...) and maven 3 using spring source tool suite. 我正在尝试使用配置文件(dev,prod ...)和使用Spring源工具套件的maven 3使Spring Boot应用程序易于包装战争。

The profiles are set and working good, I can switch profiles in application.properties using param : spring.profiles.active 配置文件已设置且运行良好,我可以使用param在application.properties中切换配置文件:spring.profiles.active

I've created application-{profiles}.properties and boot reads the property file accordingly with spring.profiles.active param set in application.properties 我已经创建了application- {profiles} .properties并通过在application.properties中设置的spring.profiles.active参数启动了相应的读取属性文件。

Now I create a maven run configuration, using in goals section : package spring-boot:repackage 现在,我在目标部分中使用以下命令创建了一个maven运行配置:package spring-boot:repackage

and I also add in parameter section : spring.profiles.active with dev as value. 并且我还添加了参数部分:spring.profiles.active,将dev作为值。

At the end I would like 3 run configurations with different values in spring.profiles.active so the package will be prepared for different environnements. 最后,我想在spring.profiles.active中使用3个具有不同值的运行配置,以便为不同的环境准备软件包。

When I run the configuration with debug mode, I can see in the test section that my current param passed in maven is correctly used (if I set dev, I see in maven test that my dev DB is called, so reads the application-dev.properties file), but after when maven is generating the final war this param don't seem to be used anymore. 当我在调试模式下运行配置时,我可以在测试部分中看到正确使用了当前在maven中传递的参数(如果设置了dev,则在maven测试中看到我的dev数据库已被调用,因此读取了application-dev .properties文件),但是当maven产生最终战争之后,似乎不再使用该参数了。

When I deploy the package, spring boot read spring.profiles.active if present in application.properties. 当我部署软件包时,spring boot会读取spring.profiles.active(如果存在于application.properties中)。 If I remove this in application.properties, boot just use the params in application.properties 如果我在application.properties中将其删除,则只需使用application.properties中的参数进行引导即可

Am I doing something wrong ? 难道我做错了什么 ? I think it's during 'repackaging' that my param set in maven is lost. 我认为在“重新包装”期间,我在maven中设置的参数丢失了。

I've also another question, I try to give a name on the final war with maven in plugin section but it doesn't seem to work like I was doing before with maven. 我还有另一个问题,我尝试在插件部分的与maven的最后一战中取一个名字,但它似乎不像我以前使用maven时那样工作。

Here is the end of my pom.xml: 这是我的pom.xml的结尾:

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <warName>stdapps</warName>
            </configuration>
        </plugin>
    </plugins>
</build>

Here is a picture of my maven configuration : 这是我的Maven配置的图片:

Maven运行配置

thanks for your help 谢谢你的帮助

Regarding the spring boot maven plugin configuration, as described in the plugin documentation , warName is not a valid parameter, finalName is. 关于spring boot maven插件配置,如插件文档中所述warName是无效参数, finalName是有效参数。

Also, from my experience, even if the documentation says that the classifier param is optional, when I tried to configure the repackage goal with a final name and an output directory, when executing the command mvn spring-boot:repackage from a terminal, the result is a build failure and a error message indicating that classifier cannot be null. 同样,根据我的经验,即使文档说分类器参数是可选的,当我尝试使用最终名称和输出目录配置重新打包目标时,从终端执行命令mvn spring-boot:repackage ,结果是构建失败,并显示一条错误消息,指示分类器不能为null。 (bug?) (错误?)

So this is the plugin configuration that works for me: 所以这是适合我的插件配置:

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <executions>
        <execution>
            <goals>
                <goal>repackage</goal>
            </goals>
            <configuration>
                <outputDirectory>deployments</outputDirectory>
                <finalName>warName</finalName>
                <classifier>classifierName</classifier>
            </configuration>
        </execution>
    </executions>
</plugin>

This generates warName-classifierName.war file in deployments folder in my project. 这将在我项目的Deployments文件夹中生成warName-classifierName.war文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM