[英]Load a property file without using PropertyPlaceholderConfigurer
I have a requirement where I have to load a property file which contains CQ5 connection details from my project and provide it as bean properties in a jar which is added in my maven dependency. 我有一个要求,我必须从我的项目中加载一个包含CQ5连接详细信息的属性文件,并将其作为bean属性提供到添加到我的maven依赖项的jar中。 My Project is using this jar to connect to CQ so I should be able to provide the CQ Connection details to that project as bean properties.
我的项目正在使用此jar连接到CQ,因此我应该能够提供该项目的CQ连接详细信息作为bean属性。 Now my project is not spring based so i cannot use
PropertyPlaceholderConfigurer
whereas the jar added as Maven dependency is Spring based. 现在我的项目不是基于Spring的,所以我不能使用
PropertyPlaceholderConfigurer
而作为Maven依赖项添加的jar是基于Spring的。
Is there any other way to replace value in below bean properties. 还有其他方法可以替换下面的bean属性中的值。
<bean id="slingJsonRequestor" class="com.my.project.content.requestor.SlingRequestor">
<constructor-arg name="suffix" value="json.js"></constructor-arg>
<constructor-arg name="resourceBlacklist" ref="slingBlacklistCache"></constructor-arg>
<property name="url" value="${cq-url}"></property>
<property name="urlCacId" value="${cq-url-cacid}"></property>
<property name="urlTemplate" value="${cq-url-template}"></property>
</bean>
Please provide a non spring solution to achieve this. 请提供非弹簧解决方案以实现此目的。
Yes, it is possible to do it with Maven. 是的,可以使用Maven做到这一点。
Maven Resources Plugin Maven资源插件
You simply add a properties element and a resource element to your pom.xml: 您只需在pom.xml中添加一个properties元素和一个resource元素:
<properties>
<myproperty>A special value</myproperty>
</properties>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/myproperties.properties</include>
</inlcudes>
</resource>
</resources>
</build>
Then if the text ${myproperty} is encountered in myproperties.properties maven will replace it with the property value from pom.xml(Not so different from Spring, hey?) 然后,如果在myproperties.properties中遇到文本$ {myproperty},则maven会将其替换为pom.xml中的属性值(与Spring没什么不同,嘿?)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.