HikariCP-Fatal exception

使用HikariCP的时候遇到这个问题:

java.lang.RuntimeException: Fatal exception during proxy generation
com.zaxxer.hikari.proxy.JavassistProxyFactory.(JavassistProxyFactory.java:61)
com.zaxxer.hikari.HikariConfig.(HikariConfig.java:

java.io.IOException: invalid constant type: 18
javassist.bytecode.ConstPool.readOne(ConstPool.java:1027)
javassist.bytecode.ConstPool.read(ConstPool.java:970)
javassist.bytecode.ConstPool.(ConstPool.java:127)
javassist.bytecode.ClassFile.read(ClassFile.java:722)
javassist.bytecode.ClassFile.(ClassFile.java:109)
javassist.CtClassType.getClassFile2(CtClassType.java:190)
javassist.CtClassType.subtypeOf(CtClassType.java:303)
javassist.CtClassType.subtypeOf(CtClassType.java:318)
javassist.CtClassType.subtypeOf(CtClassType.java:318)
javassist.compiler.MemberResolver.compareSignature(MemberResolver.java:247)
javassist.compiler.MemberResolver.lookupMethod(MemberResolver.java:119)
javassist.compiler.MemberResolver.lookupMethod(MemberResolver.java:96)
javassist.compiler.TypeChecker.atMethodCallCore(TypeChecker.java:704)
javassist.compiler.TypeChecker.atCallExpr(TypeChecker.java:681)
javassist.compiler.JvstTypeChecker.atCallExpr(JvstTypeChecker.java:156)
javassist.compiler.ast.CallExpr.accept(CallExpr.java:45)
javassist.compiler.CodeGen.doTypeCheck(CodeGen.java:241)
javassist.compiler.CodeGen.compileExpr(CodeGen.java:228)
javassist.compiler.CodeGen.atReturnStmnt2(CodeGen.java:597)
javassist.compiler.JvstCodeGen.atReturnStmnt(JvstCodeGen.java:424)
javassist.compiler.CodeGen.atStmnt(CodeGen.java:362)
javassist.compiler.ast.Stmnt.accept(Stmnt.java:49)
javassist.compiler.CodeGen.atStmnt(CodeGen.java:350)
javassist.compiler.ast.Stmnt.accept(Stmnt.java:49)
javassist.compiler.MemberCodeGen.atTryStmnt(MemberCodeGen.java:203)
javassist.compiler.CodeGen.atStmnt(CodeGen.java:366)
javassist.compiler.ast.Stmnt.accept(Stmnt.java:49)
javassist.compiler.CodeGen.atStmnt(CodeGen.java:350)
javassist.compiler.ast.Stmnt.accept(Stmnt.java:49)
javassist.compiler.CodeGen.atMethodBody(CodeGen.java:291)
javassist.compiler.Javac.compileBody(Javac.java:222)
javassist.CtBehavior.setBody(CtBehavior.java:401)
javassist.CtBehavior.setBody(CtBehavior.java:375)
com.zaxxer.hikari.proxy.JavassistProxyFactory.generateProxyClass(JavassistProxyFactory.java:193)
com.zaxxer.hikari.proxy.JavassistProxyFactory.(JavassistProxyFactory.java:86)
com.zaxxer.hikari.proxy.JavassistProxyFactory.(JavassistProxyFactory.java:57)
com.zaxxer.hikari.HikariConfig.(HikariConfig.java:32)
com.cbss.ctb.mysql.MysqlPoolManager.createPools(MysqlPoolManager.java:135)
com.cbss.ctb.mysql.MysqlPoolManager.init(MysqlPoolManager.java:167)
com.cbss.ctb.mysql.MysqlPoolManager.(MysqlPoolManager.java:36)
com.cbss.ctb.mysql.MysqlPoolManager.getInstance(MysqlPoolManager.java:47)
com.cbss.ctb.mysql.MySqlDataService.(MySqlDataService.java:33)
com.cbss.restserv.TraffProcPerf.(TraffProcPerf.java:21)
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
java.lang.reflect.Constructor.newInstance(Constructor.java:422)
com.sun.jersey.server.spi.component.ResourceComponentConstructor._construct(ResourceComponentConstructor.java:191)
com.sun.jersey.server.spi.component.ResourceComponentConstructor.construct(ResourceComponentConstructor.java:179)
com.sun.jersey.server.impl.resource.PerRequestFactory PerRequest.getInstance(PerRequestFactory.java:182)com.sun.jersey.server.impl.resource.PerRequestFactory AbstractPerRequest.getInstance(PerRequestFactory.java:144)
com.sun.jersey.server.impl.application.WebApplicationContext.getResource(WebApplicationContext.java:238)
com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:83)
com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1483)
com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1414)
com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1363)
com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1353)
com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:414)
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:708)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

—解决办法;
将HikariCP-java6升级成最新版
http://mvnrepository.com/artifact/com.zaxxer/HikariCP-java6/2.3.13

连接池代码:

public class Database
{
    private HikariDataSource dataSource;
    private Connection driverConnection;
    private Statement driverStatement;

    public Database()
    {
        boolean SQLException = false;
        try
        {
            Class.forName("com.mysql.jdbc.Driver");

            DatabasePool Pooling = new DatabasePool();
            if (!Pooling.getStoragePooling())
            {
                SQLException = true;
                return;
            }
            this.dataSource = Pooling.getDatabase();
            this.driverConnection = this.dataSource.getConnection();
            this.driverStatement = this.driverConnection.createStatement();
        }
        catch (ClassNotFoundException e)
        {
            SQLException = true;
        }
        catch (java.sql.SQLException e)
        {
            SQLException = true;
        }
        catch (Exception e)
        {
            SQLException = true;
        }
    }

    public Connection getDriverConnection(){
        return this.driverConnection;
    }

    public HikariDataSource getDataSource()
    {
        return this.dataSource;
    }
}

//

public class DatabasePool
{
    private HikariDataSource database;
    private HikariConfig databaseConfiguration;

    public boolean getStoragePooling()
    {
        try
        {
            this.databaseConfiguration = new HikariConfig();
            this.databaseConfiguration.setMaximumPoolSize(10);
            this.databaseConfiguration.setDataSourceClassName("com.mysql.jdbc.jdbc2.optional.MysqlDataSource");
            this.databaseConfiguration.addDataSourceProperty("serverName", "127.0.0.1");
            this.databaseConfiguration.addDataSourceProperty("port", "3306");
            this.databaseConfiguration.addDataSourceProperty("databaseName", "database");
            this.databaseConfiguration.addDataSourceProperty("user", "root");
            this.databaseConfiguration.addDataSourceProperty("password", "password");
            this.databaseConfiguration.setAutoCommit(true);
            this.databaseConfiguration.setMaxLifetime(120000000L);
            this.database = new HikariDataSource(this.databaseConfiguration);
        }
        catch (Exception e)
        {
            return false;
        }
        return true;
    }

    public HikariDataSource getDatabase()
    {
        return this.database;
    }
}

参考:
http://pastebin.com/y3CkQ2Wf
https://github.com/brettwooldridge/HikariCP/issues/268

你可能感兴趣的:(其他)