struts2+spring3,spring3有没有办法动态改到datasourse中的user及password

jdbc.properties

#数据库连接
jdbc.connection.driverclass=oracle.jdbc.driver.OracleDriver
jdbc.connection.url=jdbc:oracle:thin:@127.0.0.1:1521:orcl
jdbc.connection.username=test    
jdbc.connection.password=test

#c3p0连接池
acquireIncrement=3
initialPoolSize=3
maxPoolSize=15
minPoolSize=5
maxStatements=15
maxStatementsPerConnection=5



bean.xml

    <bean id="propertyConfigurer"
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
        lazy-init="false">
        <property name="locations">
            <list>
                <value>classpath*:jdbc.properties</value>
            </list>
        </property>
    </bean>       
    <!-- 配置c3p0数据源 -->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
        <property name="driverClass" value="${jdbc.connection.driverclass}" />
        <property name="jdbcUrl" value="${jdbc.connection.url}" />
        <property name="user" value="${jdbc.connection.username}" />
        <property name="password" value="${jdbc.connection.password}" />

        <property name="acquireIncrement" value="${acquireIncrement}" />
        <property name="initialPoolSize" value="${initialPoolSize}" />
        <property name="maxPoolSize" value="${maxPoolSize}" />
        <property name="minPoolSize" value="${minPoolSize}" />
        <property name="maxStatements" value="${maxStatements}" />
        <property name="maxStatementsPerConnection" value="${maxStatementsPerConnection}" />
    </bean>

    <!-- jdbc模板 -->
    <bean id="jdbcTemplate" class="org.springframework.jdbc.core.simple.SimpleJdbcTemplate">
        <constructor-arg>
            <ref bean="dataSource" />
        </constructor-arg>
    </bean>



问题是:有没有办法根据用户不同动态改变连接数据库的用户名和密码,
如用户1进来后用户名和密码如下:
jdbc.connection.username=test
jdbc.connection.password=test
用户2进来后用户名和密码如下:
jdbc.connection.username=test2
jdbc.connection.password=test2

用户2进来后用户名和密码如下:
jdbc.connection.username=test3
jdbc.connection.password=test3

因为我不想手功来改
jdbc.connection.username=
jdbc.connection.password=
之是想库里读出来后自动把取出的值赋给username和password ,有没有好的办法能实现类似的功能

你可能感兴趣的:(spring)