0

At the top of my application context I declare a PropertyPlaceholderConfigurer

...
<context:annotation-config/>

<context:property-placeholder location="classpath:foo.properties"/>
...

Later on I declare a datasource bean parameterized by properties from that properties file

<bean id="someDataSource" class="oracle.jdbc.pool.OracleDataSource" destroy-method="close">
    <property name="connectionCachingEnabled" value="true"/>
    <property name="URL" value="${database.url}"/>
    <property name="user" value="${database.user}"/>
    <property name="password" value="${database.password}"/>
</bean>

During deployment I notice that the datasource bean is created and a connection is attempted to be established BEFORE the PropertyPlaceholderConfigurer is initialized. That's causing my datasource parameterizations to not be populated.

Any idea why this might be happening?

Is there a specific order of creation for beans? Are certain beans always initialized before others? Is there a way to ensure that the PropertyPlaceholderConfigurer is loaded before all other beans?

Dakota Brown
  • 730
  • 7
  • 20
  • It is loaded before all other beans unless you are using the datasource in some other bean that is needed very early on in your startup sequence. – M. Deinum Jun 19 '15 at 06:27

2 Answers2

1

It turns out that one of the beans I defined is a MapperScannerConfigurer for mybatis that references a sqlSessionFactory.

The MapperScannerConfigurer can initialize prior to any PropertyPlaceholderConfigurer if it's initialized with deprecated bean properties

To correct the behavior, the sqlSessionFactory has to be referenced using a different bean property.

See this related post for more details

Community
  • 1
  • 1
  • After three days of tracking this down in my own application, it all seems so simple now :) Thanks for your contribution! – Dakota Brown Nov 16 '15 at 19:03
0

You need to move the <context:property-placeholder location="classpath:foo.properties"/> ahead of <context:annotation-config/>

<context:property-placeholder location="classpath:foo.properties"/> <context:annotation-config/>

Gabriel J
  • 9
  • 2