spring hibernate hibernate.connection.provider_class没有得到调用

时间:2013-04-12 06:28:52

标签: spring hibernate connection-pooling

我在我的应用程序中使用spring 3和hibernate 3.x和mule 3.x.My配置文件是

<spring:bean id="sessionFactory"
            class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
            <spring:property name="dataSource" ref="dataSource" />
            <spring:property name="packagesToScan" value="${hibernate.packagesToScan}" />
            <spring:property name="eventListeners">
                <spring:map>
                    <spring:entry key="pre-insert">
                        <spring:bean
                            class="com.myapp.listener.PreInsertOrUpdateEventListener"
                            id="preInsertOrUpdateEventListener" />
                    </spring:entry>
                    <spring:entry key="pre-update">
                        <spring:bean
                            class="com.myapp.listener.PreInsertOrUpdateEventListener"
                            id="preInsertOrUpdateEventListener" />
                    </spring:entry>
                </spring:map>
            </spring:property>
            <spring:property name="hibernateProperties">
                <spring:props>
                    <spring:prop key="hibernate.dialect">${hibernate.dialect}</spring:prop>
                    <spring:prop key="hibernate.show_sql">${hibernate.show_sql}</spring:prop>
                    <spring:prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}
                    </spring:prop>
                    <spring:prop key="hibernate.temp.use_jdbc_metadata_defaults">${hibernate.temp.use_jdbc_metadata_defaults}
                    </spring:prop>
                    <spring:prop key="hibernate.connection.provider_class">${hibernate.connection.provider_class}
                    </spring:prop>
                    <spring:prop key="hibernate.dbcp.initialSize">${hibernate.dbcp.initialSize}
                    </spring:prop>
                    <spring:prop key="hibernate.dbcp.maxActive">${hibernate.dbcp.maxActive}
                    </spring:prop>
                    <spring:prop key="hibernate.dbcp.maxIdle">${hibernate.dbcp.maxIdle}
                    </spring:prop>
                    <spring:prop key="hibernate.dbcp.minIdle">${hibernate.dbcp.minIdle}
                    </spring:prop>
                </spring:props>
            </spring:property>
        </spring:bean>

<spring:bean id="dataSource" name="dataSource"
            class="org.apache.commons.dbcp.BasicDataSource">
            <spring:property name="driverClassName" value="${db.driverClassName}" />
            <spring:property name="url" value="${db.url}" />
            <spring:property name="username" value="${db.username}" />
            <spring:property name="password" value="${db.password}" />
        </spring:bean>

我想为连接池调用我的自定义连接提供程序类,但它没有被调用。任何人都可以告诉我这是什么问题..

谢谢。

1 个答案:

答案 0 :(得分:1)

AnnotationSessionFactoryBeanLocalSessionFactoryBean用弹簧提供的LocalDataSourceConnectionProvider替换连接提供程序。因此,您必须使用它或通过扩展它来创建自己的自定义LocalSessionFactoryBean

检查LocalSessionFactoryBean源代码,了解其设置connectionProvider值的方式。

希望它有所帮助。我也在寻找一个很好的解决方案。