在Spring applicationContext.xml中使用带数据源的P6Spy [英] Usage of P6Spy with datasource in Spring applicationContext.xml
问题描述
我在Weblogic服务器和applicationContext.xml中创建了数据源I已将数据源定义为
<! - 数据源声明 - >
< bean id =DataSourceclass =org.springframework.jndi.JndiObjectFactoryBean>
< property name =jndiNamevalue =jdbc / myDS/>
< / bean>
如果我想使用P6Spy记录SQL参数,我应该如何以及在哪里添加以下是applicationcontext.xml中的内容吗?
< property name =hibernate.connection.driver_class> com.p6spy.engine。间谍。
P6SpyDriver< / property>
任何帮助都非常可观。
谢谢
使用spring集成p6spy的最简单方法是使用P6DataSource类。 P6DataSource类只是真实数据源的代理。这允许您使用任何Spring数据源工厂实现来获取真实的数据源。
< bean id =dataSource类= com.p6spy.engine.spy.P6DataSource >
< constructor-arg>
< bean id =DataSourceclass =org.springframework.jndi.JndiObjectFactoryBean>
< property name =jndiNamevalue =jdbc / myDS/>
< / bean>
< / constructor-arg>
< / bean>
如果您使用的是XADatasource,只需将类名更改为P6ConnectionPoolDataSource,如下所示。注意:P6ConnectionPoolDataSource实现了ConnectionPoolDataSource和XADataSource接口。
< bean id =dataSourceclass =com.p6spy.engine .spy.P6ConnectionPoolDataSource>
< constructor-arg>
< bean id =DataSourceclass =org.springframework.jndi.JndiObjectFactoryBean>
< property name =jndiNamevalue =jdbc / myDS/>
< / bean>
< / constructor-arg>
< / bean>
I am using Hibernate 4, Spring 3, JSF 2.0 and Weblogic 10.3.6 as server.
I have created datasource on Weblogic server and in applicationContext.xml I have defined datasource as
<!-- Data Source Declaration -->
<bean id="DataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="jdbc/myDS"/>
</bean>
If I would want to use the P6Spy for logging SQL parameters, how can and where I should add the following in applicationcontext.xml?
<property name="hibernate.connection.driver_class">com.p6spy.engine.spy.
P6SpyDriver</property>
Any help is highly appreciable.
Thanks
The easiest way to integrate p6spy using spring is to use the P6DataSource class. The P6DataSource class is just a proxy for the real data source. This lets you obtain the real data source using any of the spring data source factory implementations.
<bean id="dataSource" class="com.p6spy.engine.spy.P6DataSource">
<constructor-arg>
<bean id="DataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="jdbc/myDS"/>
</bean>
</constructor-arg>
</bean>
If you are using an XADatasource, just change the classname to P6ConnectionPoolDataSource as shown below. Note: P6ConnectionPoolDataSource implements the ConnectionPoolDataSource and XADataSource interfaces.
<bean id="dataSource" class="com.p6spy.engine.spy.P6ConnectionPoolDataSource">
<constructor-arg>
<bean id="DataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="jdbc/myDS"/>
</bean>
</constructor-arg>
</bean>
这篇关于在Spring applicationContext.xml中使用带数据源的P6Spy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!