在Spring applicationContext.xml中使用P6Spy和数据源

Jåc*_*cob 4 java logging spring hibernate p6spy

我使用Hibernate 4,Spring 3,JSF 2.0和Weblogic 10.3.6作为服务器.

我在Weblogic服务器上创建了数据源,在applicationContext.xml中我已经将数据源定义为

<!-- Data Source Declaration -->    
    <bean id="DataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="jdbc/?myDS"/>   
</bean>
Run Code Online (Sandbox Code Playgroud)

如果我想使用P6Spy记录SQL参数,我应该如何以及在何处在applicationcontext.xml中添加以下内容?

  <property name="hibernate.connection.driver_class">com.p6spy.engine.spy.
  P6SpyDriver</property>
Run Code Online (Sandbox Code Playgroud)

任何帮助都非常值得赞赏.

谢谢

qui*_*onm 6

使用spring集成p6spy的最简单方法是使用P6DataSource类.P6DataSource类只是真实数据源的代理.这使您可以使用任何spring数据源工厂实现获取实际数据源.

<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>
Run Code Online (Sandbox Code Playgroud)

如果您使用的是XADatasource,只需将类名更改为P6ConnectionPoolDataSource,如下所示.注意:P6ConnectionPoolDataSource实现ConnectionPoolDataSource和XADataSource接口.

<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>
Run Code Online (Sandbox Code Playgroud)