使用 spring 读取 war 之外的属性文件
在此处输入代码
我在 etc 文件夹中放置了一个属性文件。 “myapplication.properties”和每个子模块中的一些其他属性文件..我尝试执行以下操作
<bean class="org.springframework.web.context.support.ServletContextPropertyPlaceholderConfigurer">
<property name="searchContextAttributes" value="true"/>
<property name="contextOverride" value="true"/>
<property name="ignoreResourceNotFound" value="true"/>
<property name="locations">
<list>
<value>classpath:application.properties</value>
<value>${config}</value>
</list>
</property>
</bean>
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="ignoreUnresolvablePlaceholders" value="true"/>
</bean>
我尝试执行 mvn -Dconfig=~/my.properties jetty:run
属性是从 application.properties 读取但不用于配置。
运行应用程序时,我得到的 ${jdbc.url} 不正确。该 url 存在于 my.properties 中。 如何才能实现这一目标?
谢谢
enter code here
I have a property file placed in the etc folder. "myapplication.properties" and few other property files in each sub module.. i am try to do the following
<bean class="org.springframework.web.context.support.ServletContextPropertyPlaceholderConfigurer">
<property name="searchContextAttributes" value="true"/>
<property name="contextOverride" value="true"/>
<property name="ignoreResourceNotFound" value="true"/>
<property name="locations">
<list>
<value>classpath:application.properties</value>
<value>${config}</value>
</list>
</property>
</bean>
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="ignoreUnresolvablePlaceholders" value="true"/>
</bean>
I am trying to do mvn -Dconfig=~/my.properties jetty:run
The properties are read from application.properties but not for config..
While running application i get the ${jdbc.url} not correct .. This url is present in my.properties ..
How can this be achieved ?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这就是我所拥有的,运行它
并在 MAVEN_OPTS 中添加
-Dconfig=/var//my.properties
.. 并执行 mvn jetty:run另一种单行解决方案我发现..而不是进行详细的配置
This is what I had, to run it
And add
-Dconfig=/var//my.properties
in the MAVEN_OPTS.. and did mvn jetty:runAnother one line solution I found.. instead of making verbose configuration just do
我认为这个功能在 spring 3.1 中通过新的环境抽象变得可用。有关详细信息,请参阅以下 Spring 博客:
http://blog.springsource.com/2011/02/15/spring-3-1-m1-unified-property-management/。
如果 spring 3.1 不是一个选项,您可以将 spring xml 配置文件中的文件名和路径硬编码到某个众所周知的位置,然后开发人员可以对其进行符号链接。
I think this feature becomes available in spring 3.1 via the new Environment abstraction. See the following spring blog for details:
http://blog.springsource.com/2011/02/15/spring-3-1-m1-unified-property-management/.
If spring 3.1 is not an option you can hard-code the filename and path in the spring xml configuration file to some well-known location and then developers can symlink against it.