Glassfisj环境中SLF4J记录仪的NoClassDefFound

时间:2019-02-18 13:52:30

标签: logging java-ee glassfish

我有一个Webservlet,它具有(不注入)一个Logger:

import org.slf4j.Logger;
@WebServlet("/processForm")
public class TestServlet extends HttpServlet {
    private Logger logger;

我有一个依赖项:

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
    <version>1.7.25</version>
</dependency>

并且我可以在IntelliJ IDE的外部库中看到Logger界面。

启动Glassfish时,我得到:

  Exception while loading the app : CDI deployment failure:Error while loading class theapplication.servlets.TestServlet
org.jboss.weld.resources.spi.ResourceLoadingException: Error while loading class theapplication.servlets.TestServlet
    at org.jboss.weld.resources.ClassTransformer.getBackedAnnotatedType(ClassTransformer.java:183)
    at org.jboss.weld.resources.ClassTransformer.getBackedAnnotatedType(ClassTransformer.java:191)
    at org.jboss.weld.manager.BeanManagerImpl.createAnnotatedType(BeanManagerImpl.java:1118)
    at org.glassfish.weld.WeldDeployer.firePITEvent(WeldDeployer.java:403)
    at org.glassfish.weld.WeldDeployer.fireProcessInjectionTargetEvents(WeldDeployer.java:374)
    at org.glassfish.weld.WeldDeployer.event(WeldDeployer.java:226)
    at org.glassfish.kernel.event.EventsImpl.send(EventsImpl.java:131)
Caused by: java.lang.NoClassDefFoundError: Lorg/slf4j/Logger;
    at java.lang.Class.getDeclaredFields0(Native Method)
    at java.lang.Class.privateGetDeclaredFields(Class.java:2583)
    at java.lang.Class.getDeclaredFields(Class.java:1916)
    at org.jboss.weld.annotated.slim.backed.SecurityActions.getDeclaredFields(SecurityActions.java:49)
    at org.jboss.weld.annotated.slim.backed.BackedAnnotatedType$BackedAnnotatedFields.computeValue(BackedAnnotatedType.java:182)
    at org.jboss.weld.annotated.slim.backed.BackedAnnotatedType$BackedAnnotatedFields.computeValue(BackedAnnotatedType.java:176)
    at org.jboss.weld.util.LazyValueHolder.get(LazyValueHolder.java:46)
    at org.jboss.weld.annotated.slim.backed.BackedAnnotatedType$EagerlyInitializedLazyValueHolder.<init>(BackedAnnotatedType.java:159)
    at org.jboss.weld.annotated.slim.backed.BackedAnnotatedType$BackedAnnotatedFields.<init>(BackedAnnotatedType.java:176)
    at org.jboss.weld.annotated.slim.backed.BackedAnnotatedType$BackedAnnotatedFields.<init>(BackedAnnotatedType.java:176)
    at org.jboss.weld.annotated.slim.backed.BackedAnnotatedType.<init>(BackedAnnotatedType.java:65)
    at org.jboss.weld.annotated.slim.backed.BackedAnnotatedType.of(BackedAnnotatedType.java:47)
    at org.jboss.weld.resources.ClassTransformer$TransformClassToBackedAnnotatedType.apply(ClassTransformer.java:81)
    at org.jboss.weld.resources.ClassTransformer$TransformClassToBackedAnnotatedType.apply(ClassTransformer.java:76)
    at org.jboss.weld.util.cache.ReentrantMapBackedComputingCache.lambda$null$0(ReentrantMapBackedComputingCache.java:55)
    at org.jboss.weld.util.WeakLazyValueHolder$1.computeValue(WeakLazyValueHolder.java:35)
    at org.jboss.weld.util.WeakLazyValueHolder.get(WeakLazyValueHolder.java:53)
    at org.jboss.weld.util.cache.ReentrantMapBackedComputingCache.getValue(ReentrantMapBackedComputingCache.java:72)
    at org.jboss.weld.util.cache.ReentrantMapBackedComputingCache.getCastValue(ReentrantMapBackedComputingCache.java:78)
    at org.jboss.weld.resources.ClassTransformer.getBackedAnnotatedType(ClassTransformer.java:174)
    ... 46 more
Caused by: java.lang.ClassNotFoundException: org.slf4j.Logger
    at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1621)
    at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1471)

我不知道为什么。有帮助/提示吗?

0 个答案:

没有答案