java – Tomcat 8中DB2的Log4j jdbc appender

我正在尝试使用Log4j 2将Web应用程序生成的日志保存到DB2 10.5数据库的表中.作为servlet容器,我正在使用Tomcat 8.
我的数据源声明,在Tomcat的context.xml中:

  <Resource 
          type="javax.sql.DataSource"
          name="jdbc/NCRDS" 
          factory="org.apache.tomcat.jdbc.pool.DataSourceFactory" 
          driverClassName="com.ibm.db2.jcc.DB2Driver"
          url="jdbc:db2://192.168.1.58:50000/NCR" 
          username="admin"
          password="admin"
          initialSize="0"
          maxActive="80" 
          maxIdle = "30" 
          minIdle="20"
          timeBetweenEvictionRunsMillis="30000"
          minEvictableIdleTimeMillis="60000"
          testOnBorrow="true"
          validationQuery="VALUES 1" 
          validationInterval="30000" 
          removeAbandoned="true"
          removeAbandonedTimeout="60" 
          logAbandoned="true" 
          abandonWhenPercentageFull="60"
          jdbcInterceptors="org.apache.tomcat.jdbc.pool.interceptor.ResetAbandonedTimer"/>

appender声明insinde log4j2.xml:

 <JDBC name="databaseAppender" tableName="admin.logs">
<DataSource jndiName="java:/comp/env/jdbc/NCRDS" />
<Column name="evendDate" isEventTimestamp="true" />
<Column name="Level" pattern="%level" />
<Column name="Logger" pattern="%logger" />
<Column name="Message" pattern="%msg" />
</JDBC>

jdbc资源也在我的应用程序的web.xml文件中声明.虽然我已经设法将日志插入MySQL数据库(当然改变我的配置文件中所需的信息),但我无法在DB2中实现相同的功能.以下堆栈跟踪部分似乎是导致问题的原因:

Caused by: java.lang.AbstractMethodError: com.ibm.db2.jcc.am.po.setNString(ILjava/lang/String;)V
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.tomcat.jdbc.pool.interceptor.AbstractQueryReport$StatementProxy.invoke(AbstractQueryReport.java:233)
    at com.sun.proxy.$Proxy40.setNString(Unknown Source)
    at org.apache.logging.log4j.core.appender.db.jdbc.JdbcDatabaseManager.writeInternal(JdbcDatabaseManager.java:110)
    at org.apache.logging.log4j.core.appender.db.AbstractDatabaseManager.write(AbstractDatabaseManager.java:167)
    at org.apache.logging.log4j.core.appender.db.AbstractDatabaseAppender.append(AbstractDatabaseAppender.java:105)
    at org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:99)
    at org.apache.logging.log4j.core.config.LoggerConfig.callAppenders(LoggerConfig.java:430)
    at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:409)
    at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:367)
    at org.apache.logging.log4j.core.Logger.logMessage(Logger.java:112)
    at org.apache.logging.log4j.spi.AbstractLogger.logMessage(AbstractLogger.java:738)
    at org.apache.logging.log4j.spi.AbstractLogger.logIfEnabled(AbstractLogger.java:708)
    at org.apache.logging.log4j.spi.AbstractLogger.debug(AbstractLogger.java:237)
    at com.ikubinfo.fileservice.FileSystemFileManager.<init>(FileSystemFileManager.java:53)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147)
    ... 24 more

我似乎无法找到有关此错误的任何信息,我真的可以向自己解释出现了什么问题.我非常感谢你的帮助.
我正在使用的是:Eclipse Luna,Tomcat 8,DB2 10.5,db2jcc.jar,jdk1.7,log4j需要jar.

解决方法:

这个:引起:java.lang.AbstractMethodError:com.ibm.db2.jcc.am.po.setNString基本上说DB2驱动程序没有实现log4j试图在org.apache中使用的方法setNString(). logging.log4j.core.appender.db.jdbc.JdbcDatabaseManager.writeInternal(JdbcDatabaseManager.java:110).

现在,该怎么办我无法分辨.可能有一个参数可以指示Log4j使用setString(),或者可能是,Log4j是开源的,你可以编辑JdbcDatabaseManager类.

上一篇:java – db2jcc4.jar无效参数:未知列名


下一篇:用于在Java中保存连接字符串参数的Config文件