2012-02-05 46 views
0

我正在尝试将工作的Spring WAR移动到OSGI环境(在glassfish 3.1和蓝图,spring 3.0.5中)。 应用程序加载性能从磁盘文件,像这样:PropertyPlaceholderConfigurer在磁盘上找不到属性文件

<bean id="myProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
    <property name="location" value="${my_conf}/my.properties"/> 
    <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/> 
</bean> 

我在${my_conf}/my.properties被翻译到现有路径调试器看到(C:\的conf \ my.properties)

我使用属性jms.urlmy.properties定义在接下来的bean声明

<amq:broker useJmx="false" persistent="false" brokerName="embeddedbroker"> 
    <amq:transportConnectors> 
     <amq:transportConnector uri="tcp://${jms.url}"/> 
     <amq:transportConnector uri="vm://embeddedbroker" /> 
    </amq:transportConnectors> 
</amq:broker> 

和部署我得到一个异常"Could not resolve placeholder ${jms.url}"

为什么失败?有没有另一种方法来从磁盘上的文件加载属性?

谢谢

+0

可能重复[问题](http://stackoverflow.com/questions/4779572/could-not-resolve-placeholder-problem)。您在调试器中看到的可能会由另一个应用程序中的另一个bean加载.Context.xml – Ravi 2012-02-06 05:17:09

+0

谢谢。我试图设置一个位置路径到不存在的文件,并没有得到一个异常。我试图设置一个硬编码的路径到属性文件,并没有改变。请记住它在非osgi战争中工作 – lili 2012-02-06 09:05:04

回答

0

这不是一个解决方案,而是我的问题的解释。 问题与此bug in spring 3 and osgi有关。

我不得不打开春天日志调试级别了解它。

0

自OSGi环境,则需要弹簧OSGi的核心的jar添加到您的应用程序。看看这个link为OSGI框架配置属性占位符。

+0

谢谢。我想我不必使用osgix:cm-properties,根据这篇文章:[osgi-spring-config](http://tech-tauk.blogspot.com/2009/12/osgi-spring-configuration-admin -dynamic.html)。我错了吗? – lili 2012-02-06 17:27:08

+0

如果你不使用spring-osgi-core你将无法在你的context.xml中使用osgix标签,因为这些模式位于spring-osgi-core – Ravi 2012-02-06 17:40:00

+0

我没有使用osgix标签,而我只使用bean和amq。我正在使用spring-osgi-core jar和许多其他弹簧罐,但它不能帮助我解决所描述的问题 – lili 2012-02-07 07:52:22