Results 1 to 8 of 8

Thread: MDC in SLF4J not supported?

  1. #1
    Join Date
    Mar 2007
    Posts
    23

    Default MDC in SLF4J not supported?

    Hi guys, I'm using SLF4J but got stuck in MDC.

    Code:
    ...
    MDC.put("identifier", profile.getIdentifier());
    ...
    Code:
    [2009-02-06 00:09:31.896] server-tomcat-thread-2   ringsource.server.catalina].[localhost].[/].[dispatcher].unknown E Servlet.service() for servlet dispatcher threw exception
    java.lang.NoClassDefFoundError: org/slf4j/impl/StaticMDCBinder
    	at org.slf4j.MDC.<clinit>(MDC.java:69)
    	at com.foo.core.service.impl.DefaultHttpRequestProcessor.processInternal(DefaultHttpRequestProcessor.java:48)
    	at com.foo.core.service.impl.DefaultHttpRequestProcessor.process(DefaultHttpRequestProcessor.java:44)
    	at com.foo.core.model.HttpProfile.receive(HttpProfile.java:110)
    	at com.foo.web.action.HttpEndpoint.handleRequestInternal(HttpEndpoint.java:35)
    	at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
    	at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
    	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875)
    	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:807)
    	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
    	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:501)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    	at org.apache.catalina.valves.CometConnectionManagerValve.invoke(CometConnectionManagerValve.java:248)
    	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:568)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    	at com.springsource.server.servlet.tomcat.internal.ApplicationNameTrackingValve.invoke(ApplicationNameTrackingValve.java:74)
    	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:568)
    Code:
    Manifest-Version: 1.0
    Bundle-ManifestVersion: 2
    Bundle-Name: foo - core internal
    Bundle-SymbolicName: com.foo.core.internal
    Bundle-Version: 1.0.0.SNAPSHOT
    Import-Library: org.springframework.spring;version="[2.5,2.6)"
    Import-Bundle: com.springsource.org.eclipse.persistence;version="[1.0.0,1.1.0)";import-scope:=application,
     com.springsource.org.eclipse.persistence.jpa;version="[1.0.0,1.1.0)",
     com.springsource.javax.persistence;version="[1.0.0,1.0.0]",
     com.springsource.org.aspectj.runtime;version="1.6.0",
     com.springsource.org.aspectj.weaver;version="1.6.0",
     com.springsource.org.joda.time;version="1.5",
     com.springsource.org.quartz;version="1.6"
    Import-Package: com.foo.core.model,
     com.foo.core.service,
     com.foo.infrastructure,
     javax.annotation,
     javax.sql,
     org.apache.commons.logging,
     org.slf4j;version="1.5",
     org.slf4j.helpers;version="1.5",
     org.slf4j.impl;version="1.5",
     org.slf4j.spi;version="1.5"
    I've tried importing only org.slf4j and org.slf4j with org.slf4j.impl, still no luck. Any suggestion?

  2. #2
    Join Date
    Jul 2005
    Location
    Hamburg, Germany
    Posts
    34

    Default

    We have the same problem here. Is there any solution to this?

  3. #3
    Join Date
    Jan 2008
    Location
    Mohnton, PA USA (that's near Philadelphia)
    Posts
    2,148

    Default

    SLF4J and Log4J are part of the dmServer core and as you can see these bundles are deployed in the lib directory.

    The bundle in question is com.springsource.slf4j.simple which I supposed you've installed but probably in the wrong place. This is the bundle that has org.slf4j.impl.StaticMDCBinder class, but because it is used by dmServer logging system it must be in the lib directory and not in repository/bundles/usr.

    So to make the long story short install com.springsource.slf4j.simple into lib directory of the server and your Import-Package should work:

    Code:
    Import-Package: org.slf4j.impl;version="[1.5.6,1.5.6]",
     . . .

  4. #4
    Join Date
    Jan 2008
    Location
    Mohnton, PA USA (that's near Philadelphia)
    Posts
    2,148

    Default

    Hold it (my bad)
    Could you please post a version of DMServer you are using?
    I just tested it with 1.0.2 and it works fine.
    Just as an FYI, the org.slf4j.MDC and org.slf4j.impl.StaticMDCBinder are both loaded by the System bundle and are exported by the com.springsource.slf4j.api-1.5.6.jar bundle located in the lib directory of the server distribution.
    Also, looking at it further the NCDF is thrown by SLF4J intentionally (just look at the static initializer of MDC class), and the code points to the following link:
    http://www.slf4j.org/codes.html#no_static_mdc_binder
    It seems like in your configuration it can not fine the appropriate binding, where in my case it defaults to org.slf4j.helpers.NOPMakerAdapter which is also loaded by the system bundle and is found in com.springsource.slf4j.api-1.5.6.jar. So you might still be missing com.springsource.slf4j.simple, or any other binding. . .

  5. #5
    Join Date
    Jul 2005
    Location
    Hamburg, Germany
    Posts
    34

    Default

    We deployed logback as dependency (inside our war) to our application. This caused the error. After removing any slf4j impl and api from our war it does work. Thanks for you help.

  6. #6
    Join Date
    Jul 2005
    Location
    Hamburg, Germany
    Posts
    34

    Default

    To give a bit more insides (I hope this is correct):

    There is no slf4j implementation in the lib directory. (Only the slf4j api and the log4j and commons-logging bindings which delegate to slf4j).
    If you then use slf4j with MDC but do not supply a MDC aware implementation in the lib directory this binding could not be found. Right?

  7. #7
    Join Date
    Jan 2008
    Location
    Mohnton, PA USA (that's near Philadelphia)
    Posts
    2,148

    Default

    This would probably be more of a SLF4J question, but according to my understanding of their documentation here: http://www.slf4j.org/codes.html#no_static_mdc_binder it is correct.
    Why do you keep JARs in the WEB-INF/lib? Why not use OSGi capabilities and manage dependencies via MANIFEST?

  8. #8
    Join Date
    Jul 2005
    Location
    Hamburg, Germany
    Posts
    34

    Default

    We are currently evaluating spring-dm as alternative to plain tomcat server, since we have many memory leaks on dependent libraries (e.g. activemq, richfaces) and therefore we currently have not fully migrated to osgi.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •