简体   繁体   English

不使用PropertyPlaceholderConfigurer加载属性文件

[英]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.

相关问题 在PropertyPlaceholderConfigurer管理的属性文件中允许$字符 - Allowing $ character in a property file managed by PropertyPlaceholderConfigurer Spring PropertyPlaceholderConfigurer问题加载属性文件 - Spring PropertyPlaceholderConfigurer Issue to Load A Properties File 无法使用PropertyPlaceholderConfigurer在JNDI上下文中找到属性 - Unable to find property in JNDI context using PropertyPlaceholderConfigurer Maven项目:Spring无法使用PropertyPlaceholderConfigurer在src / main / resources中找到属性文件 - Maven Project: Spring cannot find property file inside src/main/resources using PropertyPlaceholderConfigurer 如何使用PropertyPlaceholderConfigurer使用自定义xml文件将变量加载到我的spring.xml中? - How to use a custom xml file to load variables to my spring.xml using PropertyPlaceholderConfigurer? 无法使用PropertyPlaceholderConfigurer更新配置文件 - Can not update config file using PropertyPlaceholderConfigurer 如何在JSP中使用PropertyPlaceholderConfigurer中指定的属性文件中的属性 - How to use property from property file specified in PropertyPlaceholderConfigurer in JSP 在多个项目/模块中使用多个属性文件(通过PropertyPlaceholderConfigurer) - Using multiple property files (via PropertyPlaceholderConfigurer) in multiple projects/modules PropertyPlaceholderConfigurer类中的locations属性 - locations property in PropertyPlaceholderConfigurer class 修改 PropertyPlaceholderConfigurer 的属性 - Modify property of PropertyPlaceholderConfigurer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM