在开发中运行应用程序时,很好。 当我构建战争并尝试在tomcat中部署时,它会发出以下错误:
log4j:ERROR Error initializing log4j: tried to access field org.slf4j.impl.StaticLoggerBinder.SINGLETON from class org.slf4j.LoggerFactory
java.lang.IllegalAccessError: tried to access field org.slf4j.impl.StaticLoggerBinder.SINGLETON from class org.slf4j.LoggerFactory
at org.slf4j.LoggerFactory.staticInitialize(LoggerFactory.java:83)
at org.slf4j.LoggerFactory.<clinit>(LoggerFactory.java:73)
at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:155)
at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:131)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:685)
at org.codehaus.groovy.grails.commons.DefaultGrailsApplication.<clinit>(DefaultGrailsApplication.java:82)
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 java.lang.Class.newInstance(Class.java:379)
at org.codehaus.groovy.grails.plugins.log4j.web.util.Log4jConfigListener.createGrailsApplication(Log4jConfigListener.java:54)
at org.codehaus.groovy.grails.plugins.log4j.web.util.Log4jConfigListener.contextInitialized(Log4jConfigListener.java:42)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5017)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5531)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1095)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1930)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
答案 0 :(得分:0)
根据SLF4j FAQs
此错误是由LoggerFactory的静态初始化程序引起的 类试图直接访问的SINGLETON字段 org.slf4j.impl.StaticLoggerBinder。虽然SLF4J允许这样做 1.5.5及更早版本,在1.5.6及更高版本中,SINGLETON字段已被标记为私有访问。
如果您收到上面显示的异常,那么您使用的是旧版本 slf4j-api的版本,例如1.4.3,带有slf4j的新版本 绑定,例如1.5.6。通常,这发生在您的Maven pom.ml时 文件包含hibernate 3.3.0,它声明了依赖 slf4j-api版本1.4.2。如果你的pom.xml声明了一个依赖项 slf4j绑定,说slf4j-log4j12版本1.5.6,然后你会得到 非法访问错误。在您的pom.xml文件中,明确声明一个 依赖于slf4j-api匹配声明的绑定的版本 会让问题消失。
也请参阅此answer。 您可能需要验证您的服务器是否包含slf4j-api的旧版本。