如何在jBoss 7.x上的Arquillian测试中设置p6spy驱动程序?

Bor*_*vić 2 java integration-testing p6spy jboss-arquillian jboss7.x

除了设置模块

JBOSS_HOME/modules/com/p6spy/main
Run Code Online (Sandbox Code Playgroud)

加入p6spy.jarmodule.xml说:

<module xmlns="urn:jboss:module:1.0" name="com.p6spy">
  <resources>
    <resource-root path="p6spy.jar"/>
  </resources>
  <dependencies>
    <module name="javax.api"/>
  </dependencies>
</module>
Run Code Online (Sandbox Code Playgroud)

编辑standalone-full.xml并添加条目datasources/drivers:

<driver name="p6spy" module="com.p6spy">
  <xa-datasource-class>com.p6spy.engine.spy.P6SpyDriver</xa-datasource-class>
</driver>
Run Code Online (Sandbox Code Playgroud)

添加模块依赖jboss-deployment-structure.xml:

<module name="com.p6spy"/>
Run Code Online (Sandbox Code Playgroud)

p6spy我仍然收到此错误:替换数据源定义中的原始驱动程序:

Caused by: java.lang.Exception:
  {"JBAS014771: Services with missing/unavailable dependencies" => 
    ["jboss.data-source.jboss/datasources/MyDsjboss.jdbc-driver.p6spyMissing
      [jboss.data-source.jboss/datasources/MyDsjboss.jdbc-driver.p6spy]"
    ]}
Run Code Online (Sandbox Code Playgroud)

Nik*_*dun 9

这是一个相当古老的问题,但我为了未来的读者而回答.

您不需要p6spy,JBoss AS 7提供了开箱即用的间谍功能.需要两个步骤.

  • 将以下内容放在standalone.xml的logging部分中:

    <logger category="jboss.jdbc.spy">
        <level name="DEBUG"/>
    </logger>
    
    Run Code Online (Sandbox Code Playgroud)
  • 在DataSource配置中添加spy ="true"属性,如下所示:

    <datasource jndi-name="java:jboss/datasources/testDS"
        pool-name="test" enabled="true"
        use-java-context="true" spy="true">
        <connection-url>jdbc:postgresql://localhost:5432/postgres</connection-url>
        <driver>postgresql</driver>
        <security>
            <user-name>postgres</user-name>
            <password>******</password>
        </security>
    </datasource>
    
    Run Code Online (Sandbox Code Playgroud)

这就对了.您现在已在server.log中记录了所有数据库通信.根据我的喜好,间谍日志实际上有点过于冗长,但你确实掌握了所有信息.