views:

29

answers:

1

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 problem 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!

+1  A: 

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

James Earl Douglas
Errrg! That was it. Sorta. But it definitely put me on the right track. I'll edit the main entry with details.
Risser