在我的pom.xml文件中,我设置了多个配置文件。我想在application.conf文件中使用当前配置文件的值。忍者框架文档仅提及mode configurations,但我找不到任何与配置文件配置有关的内容。
示例:文档提及
SELECT Main.DEALER_CODE
, LEFT(Main.[fees], LEN(Main.[fees]) - 1) AS [fees]
FROM
( SELECT DISTINCT vlp2.DEALER_CODE
, ( SELECT DISTINCT CAST(FUNDING_FEE_AMOUNT AS VARCHAR(20)) + ';' AS [text()]
FROM dbo.valid_lease_programs AS vlp
JOIN dbo.lease_programs AS lp ON lp.LEASE_PROGRAM = vlp.LEASE_PROGRAM
WHERE lp.LEASE_REMARKS IS NOT NULL AND vlp.DEALER_CODE = vlp2.DEALER_CODE
ORDER BY 1
FOR XML PATH('')) [fees]
FROM dbo.valid_lease_programs AS vlp2) [Main];
我如何根据当前使用的配置文件设置不同的数据库名称?
答案 0 :(得分:1)
您可以将要替换的任何内容添加为配置文件定义的属性,然后启用maven资源过滤,如下所示:
<build>
..
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
..
</build>
<profiles>
<profile>
<id>developmentProfile</id>
<properties>
<dbName>database.name=database_dev</dbName>
</properties>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
</profile>
<profile>
<id>productionProfile</id>
<properties>
<dbName>database.name=database_prod</dbName>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
</profiles>
请注意,如果您使用 spring-boot ,则应引用 application.properties 文件中的属性,以使其正常工作:
someOtherProp = something
@dbName@
之后,构建应用应该正确过滤属性:
mvn clean install -PdevelopmentProfile
结果:
someOtherProp=something
database.name=database_dev