开发者

Why would Spring be trying to use the properties variable reference string instead of the value?

Here's the problem in a nutshell:

<bean id="handlerFactory" class="com.westfieldgrp.audit.jdklogging.cpm.CPMHandlerFactory">
    <property name="schemaName" value="${env.audit.databaseSchema}" />
    <property name="bufferSize" value="${env.audit.bufferSize}" /> 
    <property name="threaded" value="${env.audit.threadedAuditHandler}" />
    <property name="dataSourceSelector" ref="dataSourceSelector" />
</bean>

bufferSize on the CPMHandlerFactory is an int. Spring is failing because it is trying to set the value to '${env.audit.bufferSize}' instead of the actual value from the properties file.

Now, when I change the name of the properties file or env.audit.bufferSize in the file, Spring complains that it can't find the property 'env.audit.bufferSize'. This says to me that it CAN find the property, but instead of setting the value to '20', it's trying to set it to '${env.audit.bufferSize}'. Can anyone explain why Spring might be doing this and what I can do about it?

Contents of the properties file below:

env.audit.databaseSchema=TDB2DATA
env.audit.dataSourceName=java:comp/env/AuditDataSourceAlias
env.audit.bufferSize=20
env.audit.threadedAuditHandler=true

Thanks, Peter

EDIT:

Found the problem thanks to Jamestastic below. Here's what it was: We have a "master" context file that looks like so:

<import resource="environmentBeans.xml" />
<import resource="serviceBeans.xml" />
<import resource="auditBeans.xml" />

The 'environmentBeans.xml' has the PropertyPlaceholderConfigurer in it. The p开发者_开发知识库roblem was, I added some code that referenced the 'auditBeans.xml' context, which of course doesn't have the configurer. I switched it to reference the 'master' context and it works great.

The key was understanding why the values wouldn't get substituted out: because there was no property configurer.

So, Thanks!


Did you remember to add <context:property-placeholder /> or a PropertyPlaceholderConfigurer bean definition to your Spring context?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜