Usage of P6Spy with datasource in Spring applicationContext.xml

后端 未结 2 1309
庸人自扰
庸人自扰 2021-01-03 05:06

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 d

相关标签:
2条回答
  • 2021-01-03 05:28

    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>
    
    0 讨论(0)
  • 2021-01-03 05:28

    You need to create bean of session factory in applicationContext.xml file as follows:

    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
            <property name="dataSource">
                <ref bean="dataSource" />
            </property>
        </bean>
        <bean id="dataSource"
            class="org.springframework.jdbc.datasource.DriverManagerDataSource">
            <property name="driverClassName" value="com.p6spy.engine.spy.
      P6SpyDriver" />
            <property name="url" value="jdbc\:mysql\://localhost\:3306/testdb" />
            <property name="username" value="my_username" />
            <property name="password" value="my_password" />
        </bean>
    

    Please refer to: http://www.mkyong.com/hibernate/how-to-display-hibernate-sql-parameter-values-solution/ for more about P6Spy library.

    We can omit "dataSource" bean and directly write properties. Ref: how to configure hibernate config file for sql server

    0 讨论(0)
提交回复
热议问题