2

当我启动 JBOSS AS 6.1 时出现链接错误HikariDataSource。如何解决这个问题?

我使用 hikariCP 1.3.3:

  <dependency>
     <groupId>com.zaxxer</groupId>
     <artifactId>HikariCP</artifactId>
     <version>1.3.3</version>
  </dependency>

Spring 3.2、JBOSS AS 6.1、Hibernate 3.6.6(与 JBOSS 捆绑)。我删除了 persistence.xml 并使用以下LocalContainerEntityManagerFactoryBean方法以编程方式配置了我的数据源:http ://www.baeldung.com/2011/12/13/the-persistence-layer-with-spring-3-1-and-jpa/

我的 DS 我配置简单:

   @Bean
   public DataSource dataSource() {
      HikariDataSource ds = new HikariDataSource(); //here i get the linkageError
      ds.setMaximumPoolSize(15);
      ds.setDataSourceClassName("com.microsoft.sqlserver.jdbc.SQLServerDataSource");
      ds.addDataSourceProperty("serverName", "localhost");
      ds.addDataSourceProperty("databaseName", "dbtest");
      ds.addDataSourceProperty("user", "dbtest");
      ds.addDataSourceProperty("password", "dbtest");
      ds.setPoolName("springHikariCp");
      return ds;
   }

堆栈跟踪的结尾是:

Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public javax.sql.DataSource com.company.test.PersistenceJPAConfig.dataSource()] threw exception; nested exception is java.lang.ExceptionInInitializerError
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:181) [:3.2.0.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:570) [:3.2.0.RELEASE]
    ... 135 more
Caused by: java.lang.ExceptionInInitializerError
    at com.zaxxer.hikari.HikariConfig.<clinit>(HikariConfig.java:77) [:]
    at com.company.test.PersistenceJPAConfig.dataSource(PersistenceJPAConfig.java:115) [:]
    at com.company.test.PersistenceJPAConfig$$EnhancerByCGLIB$$2cad8762.CGLIB$dataSource$3(<generated>) [:]
    at com.company.test.PersistenceJPAConfig$$EnhancerByCGLIB$$2cad8762$$FastClassByCGLIB$$7a8bcfa3.invoke(<generated>) [:]
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) [:3.2.0.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:285) [:3.2.0.RELEASE]
    at com.company.test.PersistenceJPAConfig$$EnhancerByCGLIB$$2cad8762.dataSource(<generated>) [:]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.7.0_11]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [:1.7.0_11]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [:1.7.0_11]
    at java.lang.reflect.Method.invoke(Method.java:601) [:1.7.0_11]
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:160) [:3.2.0.RELEASE]
    ... 136 more
Caused by: java.lang.RuntimeException: javassist.CannotCompileException: by java.lang.LinkageError: loader (instance of  org/jboss/classloader/spi/base/BaseClassLoader): attempted  duplicate class definition for name: "com/zaxxer/hikari/proxy/ProxyFactory"
    at com.zaxxer.hikari.proxy.JavassistProxyFactory.<clinit>(JavassistProxyFactory.java:58) [:]
    ... 148 more
Caused by: javassist.CannotCompileException: by java.lang.LinkageError: loader (instance of  org/jboss/classloader/spi/base/BaseClassLoader): attempted  duplicate class definition for name: "com/zaxxer/hikari/proxy/ProxyFactory"
    at javassist.ClassPool.toClass(ClassPool.java:1099) [:6.1.0.Final]
    at javassist.CtClass.toClass(CtClass.java:1265) [:6.1.0.Final]
    at com.zaxxer.hikari.proxy.JavassistProxyFactory.modifyProxyFactory(JavassistProxyFactory.java:131) [:]
    at com.zaxxer.hikari.proxy.JavassistProxyFactory.<clinit>(JavassistProxyFactory.java:54) [:]
    ... 148 more
Caused by: java.lang.LinkageError: loader (instance of  org/jboss/classloader/spi/base/BaseClassLoader): attempted  duplicate class definition for name: "com/zaxxer/hikari/proxy/ProxyFactory"
    at java.lang.ClassLoader.defineClass1(Native Method) [:1.7.0_11]
    at java.lang.ClassLoader.defineClass(ClassLoader.java:791) [:1.7.0_11]
    at java.lang.ClassLoader.defineClass(ClassLoader.java:634) [:1.7.0_11]
    at sun.reflect.GeneratedMethodAccessor131.invoke(Unknown Source) [:1.7.0_11]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [:1.7.0_11]
    at java.lang.reflect.Method.invoke(Method.java:601) [:1.7.0_11]
    at javassist.ClassPool.toClass2(ClassPool.java:1112) [:6.1.0.Final]
    at javassist.ClassPool.toClass(ClassPool.java:1093) [:6.1.0.Final]
    ... 151 more
4

2 回答 2

0

我会建议两件事。首先,我建议将 HikariCP 升级到最新版本 1.3.5。

其次,错误似乎与类加载器有关,异常java.lang.ExceptionInInitializerError表明静态类初始化以HikariConfig某种方式执行了两次。只有当有两个类加载器引用同一个 HikariCP jar 时,这才是可能的。确保 HikariCP jar 不在 JBoss 的全局库目录中,而是位于应用程序的容器库目录中。如果有多个应用程序容器,HikariCP jar 应该分别位于每个容器中。

于 2014-04-12T07:04:59.310 回答
0

在 JBOSS AS 6.1 上,这个问题的解决方案是我把 HikariCP-1.3.5.jar \server\app\lib 和 pom.xml 设置为provided. 当我将应用程序迁移到 WildFly 8 时,Hikari 的工作方式为compile.

于 2014-04-23T11:28:46.417 回答