首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

log4j配置文件启动项目报错。解决方案

2012-03-18 
log4j配置文件启动项目报错。属性文件配置如下:XML codelog4j.rootLoggerINFO,dblog4j.appender.dborg.ap

log4j配置文件启动项目报错。
属性文件配置如下:

XML code
log4j.rootLogger=INFO,db   log4j.appender.db=org.apache.log4j.jdbc.JDBCAppender   log4j.appender.db.BufferSize=10      log4j.appender.db.driver=net.sourceforge.jtds.jdbc.Driver                      log4j.appender.db.URL=jdbc:jtds:sqlserver://server:1434/pcbsyn log4j.appender.db.user=sa  log4j.appender.db.password=711  log4j.appender.db.sql=insert into logInfo(userId,userName,lclass,lmethod,lTime,llevel,message) values ('%X{userId}','%X{userName}','%C','%M','%d{yyyy-MM-dd HH:mm:ss}','%p','%m')    log4j.appender.db.layout=org.apache.log4j.PatternLayout  

端口是1434 数据库是pcbsyn 。这个jtds的jar文件 在WEB-INF\lib目录下面是存在的! jtds-1.2.5.jar
数据库是 sql server 2000 sp4

Java code
log4j:ERROR Failed to load driverjava.lang.ClassNotFoundException: net.sourceforge.jtds.jdbc.Driver                          at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1645)    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1491)    at java.lang.Class.forName0(Native Method)    at java.lang.Class.forName(Class.java:169)    at org.apache.log4j.jdbc.JDBCAppender.setDriver(JDBCAppender.java:351)    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)    at java.lang.reflect.Method.invoke(Method.java:597)    at org.apache.log4j.config.PropertySetter.setProperty(PropertySetter.java:206)    at org.apache.log4j.config.PropertySetter.setProperty(PropertySetter.java:165)    at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:130)    at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:97)    at org.apache.log4j.PropertyConfigurator.parseAppender(PropertyConfigurator.java:689)    at org.apache.log4j.PropertyConfigurator.parseCategory(PropertyConfigurator.java:647)    at org.apache.log4j.PropertyConfigurator.configureRootCategory(PropertyConfigurator.java:544)    at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:440)    at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:476)    at org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:471)    at org.apache.log4j.LogManager.<clinit>(LogManager.java:125)    at org.apache.log4j.Logger.getLogger(Logger.java:105)    at org.apache.commons.logging.impl.Log4JLogger.getLogger(Log4JLogger.java:289)    at org.apache.commons.logging.impl.Log4JLogger.<init>(Log4JLogger.java:109)    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)    at org.apache.commons.logging.impl.LogFactoryImpl.createLogFromClass(LogFactoryImpl.java:1116)    at org.apache.commons.logging.impl.LogFactoryImpl.discoverLogImplementation(LogFactoryImpl.java:914)    at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:604)    at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:336)    at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:310)    at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:685)    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:183)    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4135)    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4630)    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:546)    at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1041)    at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:964)    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:502)    at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1277)    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:321)    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)    at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:445)    at org.apache.catalina.core.StandardService.start(StandardService.java:519)    at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)    at org.apache.catalina.startup.Catalina.start(Catalina.java:581)    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)    at java.lang.reflect.Method.invoke(Method.java:597)    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414) 



[解决办法]
单独写个main程序
Class.forName("net.sourceforge.jtds.jdbc.Driver");
看看

[解决办法]


Java code
log4j:ERROR Failed to load driver 

热点排行