0

我目前正在调试部署在 JBoss EAP 6.4.0.GA 上的应用程序,我想使用P6Spy检查数据库返回的内容。我从 Maven下载了文件并按照说明进行操作,它们是:

  • /usr/local/jboss6/modules/com/p6spy/main/包含 P6Spy JAR 和module.xml

    <module xmlns="urn:jboss:module:1.0" name="com.p6spy">
        <resources>
            <resource-root path="p6spy-3.9.1.jar"/>
        </resources>
        <dependencies>
            <module name="javax.api"/>
            <module name="javax.transaction.api"/>
            <!-- make sure to refer to module holding real driver -->
            <module name="com.mysql"/>
        </dependencies>
    </module>
    
  • spy.properties与内容在同一文件夹中创建一个(为了便于访问)

    modulelist=com.p6spy.engine.spy.P6SpyFactory,com.p6spy.engine.logging.P6LogFactory
    driverlist=com.mysql.jdbc.Driver
    autoflush=true
    reloadproperties=true
    reloadpropertiesinterval=60
    appender=com.p6spy.engine.spy.appender.FileLogger
    logfile=/usr/local/jboss6/standalone/log/spy.log
    excludebinary=false
    
  • standalone.xml文件中,添加以下系统属性以取属性文件

    <system-properties>
        ...
        <property name="spy.properties" value="/usr/local/jboss6/modules/com/p6spy/main/spy.properties"/>
        ...
    </system-properties>
    

    然后修改数据源以更改连接 URL 并使用新的驱动程序

    <subsystem xmlns="urn:jboss:domain:datasources:1.2">
        <datasources>
            <datasource jta="false" jndi-name="java:jboss/myDataSource" pool-name="myDataSource" enabled="true" use-java-context="true">
                <connection-url>jdbc:p6spy:mysql://my-host/my-database?noAccessToProcedureBodies=true</connection-url>
                <driver-class>com.mysql.jdbc.Driver</driver-class> <!-- I also tried changing it to the P6Spy class, as well as removing this line -->
                <driver>p6spy</driver>
                <security>
                    <user-name>credentials</user-name>
                    <password>credentials</password>
                </security>
                <validation>
                    <valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLValidConnectionChecker"/>
                    <validate-on-match>true</validate-on-match>
                    <exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLExceptionSorter"/>
                </validation>
                <statement>
                    <prepared-statement-cache-size>25</prepared-statement-cache-size>
                </statement>
            </datasource>
            <drivers>
                <driver name="p6spy" module="com.p6spy">
                    <driver-class>com.p6spy.engine.spy.P6SpyDriver</driver-class>
                </driver>
                <driver name="h2" module="com.h2database.h2">
                    <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
                </driver>
                <driver name="mysql" module="com.mysql">
                    <driver-class>com.mysql.jdbc.Driver</driver-class>
                </driver>
            </drivers>
        </datasources>
    </subsystem>
    

然后我重新启动我的服务器。在日志中,JBoss 可以识别 P6Spy 驱动程序和数据源,但是当应用程序开始初始化时会发生错误并且部署会停止。

15:24:47,923 ERROR [org.springframework.boot.SpringApplication] (ServerService Thread Pool -- 64) Application startup failed: org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name '[....]': Unsatisfied dependency expressed through field 'repository';
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '[....]' defined in class path resource [MyConfig.class]: Bean instantiation via factory method failed;
nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.modeshape.jcr.JcrRepository]: Factory method '[....]' threw exception;
nested exception is MyException: An error has occurred while the application attempted to create the repository
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:586) [spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87) [spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:364) [spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1268) [spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:551) [spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:481) [spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:312) [spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) [spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:308) [spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) [spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:372) [spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1177) [spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1072) [spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:511) [spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:481) [spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:312) [spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) [spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:308) [spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) [spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.initMessageSource(AbstractApplicationContext.java:713) [spring-context-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:530) [spring-context-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:123) [spring-boot-1.5.22.RELEASE.jar:1.5.22.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:666) [spring-boot-1.5.22.RELEASE.jar:1.5.22.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:353) [spring-boot-1.5.22.RELEASE.jar:1.5.22.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:300) [spring-boot-1.5.22.RELEASE.jar:1.5.22.RELEASE]
    at org.springframework.boot.web.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:151) [spring-boot-1.5.22.RELEASE.jar:1.5.22.RELEASE]
    at org.springframework.boot.web.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:131) [spring-boot-1.5.22.RELEASE.jar:1.5.22.RELEASE]
    at org.springframework.boot.web.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:91) [spring-boot-1.5.22.RELEASE.jar:1.5.22.RELEASE]
    at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:169) [spring-web-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    at org.jboss.as.web.deployment.JBossContextConfig.lifecycleEvent(JBossContextConfig.java:187) [jboss-as-web-7.5.0.Final-redhat-21.jar:7.5.0.Final-redhat-21]
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:115) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:3775) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]
    at org.jboss.as.web.deployment.WebDeploymentService.doStart(WebDeploymentService.java:163) [jboss-as-web-7.5.0.Final-redhat-21.jar:7.5.0.Final-redhat-21]
    at org.jboss.as.web.deployment.WebDeploymentService.access$000(WebDeploymentService.java:61) [jboss-as-web-7.5.0.Final-redhat-21.jar:7.5.0.Final-redhat-21]
    at org.jboss.as.web.deployment.WebDeploymentService$1.run(WebDeploymentService.java:96) [jboss-as-web-7.5.0.Final-redhat-21.jar:7.5.0.Final-redhat-21]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [rt.jar:1.8.0_111]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [rt.jar:1.8.0_111]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_111]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_111]
    at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_111]
    at org.jboss.threads.JBossThread.run(JBossThread.java:122)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '[....]' defined in class path resource [MyConfig.class]: Bean instantiation via factory method failed;
nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.modeshape.jcr.JcrRepository]: Factory method '[....]' threw exception;
nested exception is MyException: An error has occurred while the application attempted to create the repository
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) [spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1177) [spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1072) [spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:511) [spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:481) [spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:312) [spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) [spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:308) [spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) [spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:211) [spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1131) [spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1059) [spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:583) [spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    ... 40 more
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.modeshape.jcr.JcrRepository]: Factory method '[....]' threw exception;
nested exception is MyException: An error has occurred while the application attempted to create the repository
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) [spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) [spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    ... 52 more
Caused by: MyException: An error has occurred while the application attempted to create the repository
    at [....]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.8.0_111]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) [rt.jar:1.8.0_111]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.8.0_111]
    at java.lang.reflect.Method.invoke(Method.java:498) [rt.jar:1.8.0_111]
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) [spring-beans-4.3.25.RELEASE.jar:4.3.25.RELEASE]
    ... 53 more
Caused by: javax.jcr.RepositoryException: Error while starting '[....]' repository: java.sql.SQLException: javax.resource.ResourceException: IJ000453: Unable to get managed connection for java:jboss/myDataSource
    at org.modeshape.jcr.JcrRepository.login(JcrRepository.java:634) [modeshape-jcr-5.4.1.Final.jar:5.4.1.Final]
    at org.modeshape.jcr.JcrRepository.login(JcrRepository.java:598) [modeshape-jcr-5.4.1.Final.jar:5.4.1.Final]
    at org.modeshape.jcr.JcrRepository.login(JcrRepository.java:139) [modeshape-jcr-5.4.1.Final.jar:5.4.1.Final]
    at [....]
    ... 63 more
Caused by: org.modeshape.persistence.relational.RelationalProviderException: java.sql.SQLException: javax.resource.ResourceException: IJ000453: Unable to get managed connection for java:jboss/myDataSource
    at org.modeshape.persistence.relational.DataSourceManager.newConnection(DataSourceManager.java:112) [modeshape-persistence-relational-5.4.1.Final.jar:5.4.1.Final]
    at org.modeshape.persistence.relational.DataSourceManager.<init>(DataSourceManager.java:53) [modeshape-persistence-relational-5.4.1.Final.jar:5.4.1.Final]
    at org.modeshape.persistence.relational.RelationalDb.<init>(RelationalDb.java:64) [modeshape-persistence-relational-5.4.1.Final.jar:5.4.1.Final]
    at org.modeshape.persistence.relational.RelationalProvider.getDB(RelationalProvider.java:34) [modeshape-persistence-relational-5.4.1.Final.jar:5.4.1.Final]
    at org.modeshape.persistence.relational.RelationalProvider.getDB(RelationalProvider.java:27) [modeshape-persistence-relational-5.4.1.Final.jar:5.4.1.Final]
    at org.modeshape.schematic.Schematic.getDbFromProvider(Schematic.java:91) [modeshape-schematic-5.4.1.Final.jar:5.4.1.Final]
    at org.modeshape.schematic.Schematic.lambda$getDb$9(Schematic.java:74) [modeshape-schematic-5.4.1.Final.jar:5.4.1.Final]
    at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) [rt.jar:1.8.0_111]
    at java.util.Spliterators$IteratorSpliterator.tryAdvance(Spliterators.java:1812) [rt.jar:1.8.0_111]
    at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126) [rt.jar:1.8.0_111]
    at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:498) [rt.jar:1.8.0_111]
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:485) [rt.jar:1.8.0_111]
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471) [rt.jar:1.8.0_111]
    at java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:152) [rt.jar:1.8.0_111]
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) [rt.jar:1.8.0_111]
    at java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:464) [rt.jar:1.8.0_111]
    at org.modeshape.schematic.Schematic.getDb(Schematic.java:76) [modeshape-schematic-5.4.1.Final.jar:5.4.1.Final]
    at org.modeshape.jcr.Environment.getDb(Environment.java:59) [modeshape-jcr-5.4.1.Final.jar:5.4.1.Final]
    at org.modeshape.jcr.JcrRepository$RunningState.<init>(JcrRepository.java:1037) [modeshape-jcr-5.4.1.Final.jar:5.4.1.Final]
    at org.modeshape.jcr.JcrRepository$RunningState.<init>(JcrRepository.java:939) [modeshape-jcr-5.4.1.Final.jar:5.4.1.Final]
    at org.modeshape.jcr.JcrRepository.doStart(JcrRepository.java:375) [modeshape-jcr-5.4.1.Final.jar:5.4.1.Final]
    at org.modeshape.jcr.JcrRepository.login(JcrRepository.java:632) [modeshape-jcr-5.4.1.Final.jar:5.4.1.Final]
    ... 67 more
Caused by: java.sql.SQLException: javax.resource.ResourceException: IJ000453: Unable to get managed connection for java:jboss/myDataSource
    at org.jboss.jca.adapters.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:151)
    at org.modeshape.persistence.relational.DataSourceManager.newConnection(DataSourceManager.java:106) [modeshape-persistence-relational-5.4.1.Final.jar:5.4.1.Final]
    ... 88 more
Caused by: javax.resource.ResourceException: IJ000453: Unable to get managed connection for java:jboss/myDataSource
    at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.getManagedConnection(AbstractConnectionManager.java:421)
    at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.getManagedConnection(AbstractConnectionManager.java:327)
    at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.allocateConnection(AbstractConnectionManager.java:510)
    at org.jboss.jca.adapters.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:143)
    ... 89 more
Caused by: javax.resource.ResourceException: IJ000658: Unexpected throwable while trying to create a connection: null
    at org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreArrayListManagedConnectionPool.getConnection(SemaphoreArrayListManagedConnectionPool.java:421)
    at org.jboss.jca.core.connectionmanager.pool.AbstractPool.getSimpleConnection(AbstractPool.java:453)
    at org.jboss.jca.core.connectionmanager.pool.AbstractPool.getConnection(AbstractPool.java:425)
    at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.getManagedConnection(AbstractConnectionManager.java:354)
    ... 92 more
Caused by: javax.resource.ResourceException: Could not create connection
    at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.getLocalManagedConnection(LocalManagedConnectionFactory.java:356)
    at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.createManagedConnection(LocalManagedConnectionFactory.java:304)
    at org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreArrayListManagedConnectionPool.createConnectionEventListener(SemaphoreArrayListManagedConnectionPool.java:834)
    at org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreArrayListManagedConnectionPool.getConnection(SemaphoreArrayListManagedConnectionPool.java:379)
    ... 95 more
Caused by: javax.resource.ResourceException: Wrong driver class [class com.mysql.jdbc.Driver] for this connection URL [jdbc:p6spy:mysql://my-host/my-database?noAccessToProcedureBodies=true]
    at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.getLocalManagedConnection(LocalManagedConnectionFactory.java:330)
    ... 98 more

这是一个使用 Modeshape 5.4.1.Final 的应用程序,当存储库 bean 尝试从数据源获取连接时会发生错误。

有没有我错过的配置?

4

1 回答 1

0

我发现搞乱设置的元素<driver-class><datasource>. 它应该有 P6Spy 驱动程序

<driver-class>com.p6spy.engine.spy.P6SpyDriver</driver-class>

或完全删除它。

一开始这对我不起作用的原因是我正在编辑standalone.xml文件,然后使用jboss-cli.sh --connect --command=:reload. 这适用于大多数配置更改,但对于这部分来说还不够。您必须关闭服务器,然后重新启动它才能进行此更改。

于 2022-01-06T19:36:52.490 回答