Spring: PlaceholderConfigurer
От: purser Россия  
Дата: 05.03.19 08:15
Оценка:
Есть файл с пропертями, которые используются в бине dataSource. Есть ещё проперти, которые хранятся в таблице БД и достаются с помощью dataSource.
Проблема в том, что dataSource используется до того, как его свойства резольвятся, так как при запуске получаю "Could not load JDBC driver class [${db.driver}]"
Как зарезолвить свойства dataSource до его использования ?

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:sws="http://www.springframework.org/schema/web-services"
       xmlns:util="http://www.springframework.org/schema/util"
       xsi:schemaLocation="http://www.springframework.org/schema/beans

   http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
   http://www.springframework.org/schema/web-services
   http://www.springframework.org/schema/web-services/web-services-2.0.xsd
   http://www.springframework.org/schema/context
   http://www.springframework.org/schema/context/spring-context-3.0.xsd
   http://www.springframework.org/schema/util 
   http://www.springframework.org/schema/util/spring-util.xsd">

    <context:component-scan base-package="..."/>
    <bean id="dataSource"  class="org.springframework.jdbc.datasource.DriverManagerDataSource">
            <property name="driverClassName" value="${db.driver}"/>
            <property name="url" value="${db.url}"/>
            <property name="username" value="${db.username}"/>
            <property name="password" value="${db.password}"/>
    </bean>
    <context:property-placeholder location="classpath:config.xml"/>
    <bean class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer">
        <property name="ignoreUnresolvablePlaceholders" value="true"/>
        <property name="properties">
            <bean class="org.apache.commons.configuration.ConfigurationConverter" factory-method="getProperties">
                <constructor-arg>
                    <bean class="org.apache.commons.configuration.DatabaseConfiguration" depends-on="dataSource">
                        <constructor-arg><ref bean="dataSource" /></constructor-arg>
                        <constructor-arg value="TABLE.COMMON_SQL" />
                        <constructor-arg value="PARAM_NAME" />
                        <constructor-arg value="PARAM_VALUE" />
                    </bean>
                     </constructor-arg>
            </bean>
        </property>
    </bean>
</beans>
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.