我的应用程序中有一个自定义记录器,扩展了Log4j记录器 在摘录下方
public static CustomLogger getLogger(@SuppressWarnings("rawtypes") Class clazz) {
return (CustomLogger) Logger.getLogger(clazz.getName(), customLoggerFactory);
}
public class CustomLoggerFactory implements LoggerFactory{
@Override
public Logger makeNewLoggerInstance(String name) {
return new CustomLogger(name);
}
/** The constructor should be public as it will
* be called by configurators in different packages.
*/
public CustomLoggerFactory(){
}
}
在我的代码中,我称之为
private static final CustomLogger LOGGER = CustomLogger
.getLogger(Myclass.class);
在log 4j.properties中,我定义了一个自定义记录器,如下所示
log4j.appender.CUSTOM=org.apache.log4j.RollingFileAppender
log4j.appender.CUSTOM.File=${CONFIG}/log/mycustiom_logs.log
log4j.appender.CUSTOM.Append=true
log4j.appender.CUSTOM.MaxFileSize=1024KB
log4j.appender.CUSTOM.MaxBackupIndex=15
log4j.appender.CUSTOM.layout=org.apache.log4j.PatternLayout
log4j.appender.CUSTOM.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss} [ %-5p ] [ %20c ] [%L]- %-m %n
log4j.logger.com.test.Myclass=DEBUG,CUSTOM
但是因为bean的实例化失败而得到错误;嵌套异常是
java.lang.NoClassDefFoundError: Could not initialize class com.test.Myclass
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:107)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1456)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1197)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:323)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:973) ............
而当我将初始化更改为
时import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
....
private static final LOGGER LOGGER = LoggerFactory
.getLogger(Myclass.class);
我能够看到我的日志被重定向到appender中提到的单独日志文件。
有人可以帮我修理。如果您需要任何其他信息,请告诉我
Hi Fildor, 请在下面找到完整的例外跟踪
org.springframework.beans.factory.BeanCreationException:创建名称为' testing_flag'的bean时出错在URL [file:file:/home/test/spring_defn.xml]中定义:无法解析对bean&service; service'的引用同时设置bean属性' myclassimpl&#39 ;;嵌套异常是org.springframework.beans.factory.BeanCreationException:创建名称为' service'的bean时出错。在URL [file:file:/home/test/spring_defn.xml]中定义:bean的实例化失败;嵌套异常是java.lang.NoClassDefFoundError:无法初始化类com.test.Myclass 在org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328) 在org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:107) 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1456) 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1197) 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) 在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:323) 在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195) 在org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:973) 在com.ericsson.cac.iam.v2.authorize.service.view.IAMAuthorizeService.toggleHardLockFlag(IAMAuthorizeService.java:686) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在java.lang.reflect.Method.invoke(Method.java:497) 在org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:168) 在org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:269) 在org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:227) 在org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:216) 在org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:541) 在org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:523) 在org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:125) 在org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:208) 在org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55) 在org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:50) 在javax.servlet.http.HttpServlet.service(HttpServlet.java:847) 在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:295) 在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) 在org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:231) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:149) at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:169) 在org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:150) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:97) 在org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:102) 在org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:344) 在org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:854) 在org.apache.coyote.http11.Http11Protocol $ Http11ConnectionHandler.process(Http11Protocol.java:653) 在org.apache.tomcat.util.net.JIoEndpoint $ Worker.run(JIoEndpoint.java:926) 在java.lang.Thread.run(Thread.java:745) 引起:org.springframework.beans.factory.BeanCreationException:创建名称为' service'的bean时出错在URL [file:file:/home/test/spring_defn.xml]中定义:bean的实例化失败;嵌套异常是java.lang.NoClassDefFoundError:无法初始化类com.test.Myclass 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1076) 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1008) 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504) 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) 在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:323) 在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195) 在org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:320) ......还有37个 引起:java.lang.NoClassDefFoundError:无法初始化类com.test.Myclass at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:422) 在org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:148) 在org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:89) 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1069) ... 43更多