我有一个Web应用程序两个不同的配置文件:“test”和“dev”,然后我有2个包含文件的文件夹/opt/myApp/dev
和/opt/myApp/test
。
我需要构建我的App,将参数发送到gradle,以便根据配置文件定义路径。
在我的spring application-context.xml中,我有以下内容:
<bean id="myBean" class="com.myClass">
<property name="locations" value="file:/opt/myApp/${profile}"</property>
</bean>
如果我做不到这样的话会很好的:
gradle build -Pprofile
Gradle脚本可以完成工作
我查看了文档和stackoverflow,发现了有关过滤器的信息。但是我无法使它工作。
我正在尝试this和其他类似的东西。
最佳答案
可能有一种更清洁的方法,但是类似:
application-context.xml:
<bean id="myBean" class="com.myClass">
<property name="locations" value="file:/opt/myApp/@profile@"</property>
</bean>
build.gradle:
import org.apache.tools.ant.filters.*
apply plugin: 'java'
if (! hasProperty("profile")) {
ext.profile = "dev"
}
processResources {
filter(ReplaceTokens, tokens: [profile: profile])
}
然后像这样调用它:
gradle -Pprofile=test
关于spring - 可以在 Spring 上下文中使用gradle替换值吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22336371/