2

I have the project structure as following -

Facade -> Service-> DAO

In the DAO layer, when the beans are initialized then many dependencies are injected from a property file. Therefore, the properties file must be read first and then the remaining dao beans must be created. When the application is started then it gives an error that Spring cannot resolve a placeholder.

The DAO-application-context.xml is like-

<bean 
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">

    <property name="prop">
        <value>app.properties</value>
    </property>
</bean>

<import resource = "a-dao.xml" />
<import resource = "b-dao.xml" />
<import resource = "c-dao.xml" />

Now in all the child application contexts i.e. a-dao, etc, we have-

<bean ....>
  <property name = "xyz">
    <value>${appValue}<value/>
  </property>
<bean>

The error received is that appValue cannot be resolved. I think that it may be due to incorrect sequence of bean creation. However, the same config is working in another larger project.

I have checked Order of Spring Bean Initialization but implementing that solution would not be feasible. Is there any other way ?

harsrawa
  • 422
  • 5
  • 18

1 Answers1

0

Reg this Block of Configuration, property prop seems to be wrong

<bean 
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">

<property name="prop">
    <value>app.properties</value>
</property>
</bean>

According to the Spring documentation You could use the property location or locations to set the one or multiple values of the properties file.

So the code should be refactored to

<bean 
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
    <value>app.properties</value>
</property>
</bean>
resatz
  • 536
  • 3
  • 8