Sping Boot 应用程序使用Maven,构建与EnvFile

yrdbyhpb  于 9个月前  发布在  Maven
关注(0)|答案(1)|浏览(133)

我开始使用maven创建一个Sping Boot 应用程序。
我不想使用maven命令部署项目。application.properties

spring.config.import=optional:file:env.properties
spring.datasource.url=${DATA_SOURCE_URL}
spring.datasource.username=${DB_USER}
spring.datasource.password=${DB_PASSWORD}
spring.datasource.driver-class-name=org.mariadb.jdbc.Driver
spring.jpa.hibernate.ddl-auto = update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
jwt.secret = ${SECRET}

字符串
正如你所看到的,我导入了一个名为env.properties的文件,但是我不想每次使用mvn clean install命令时都导入它。
你能帮我找到正确的命令或配置我的pom.xml插件吗?

3ks5zfa0

3ks5zfa01#

您现在的位置:
要从pom.xml文件导入应用程序属性,您必须:
<properties>标记中设置参数和值的名称:

<properties>
    <spring.active.profile>conf</spring.active.profile>
</properties>

字符串
第二个你必须加上spring-boot-maven-pluginresource,它们指向application.properties

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <includes>
                    <include>application.properties</include>
                </includes>
            </resource>
        </resources>
    </build>


然后在application.properties文件中,您将能够访问参数作为下一个:

[email protected]@


另外,如果您不喜欢这种方法,可以使用Properties Maven Plugin

相关问题