dozer 5.3.1 WebSphere 8 ClassNotFoundException on class-a converter in mappings.xml

399 views
Skip to first unread message

Robert Glover Jr

unread,
Mar 28, 2013, 2:52:57 PM3/28/13
to dozer-...@googlegroups.com
    I have a mappings.xml file which contains the names of java classes.  Dozer 5.3.1 finds the classes okay when I invoke dozer from a Servlet by clicking a button.   What happens under the covers is that dozer uses commons-lang-2.5's org.apache.commons.lang.ClassUtils.java  to issue these two statements:

 ClassLoader contextCL = Thread.currentThread().getContextClassLoader();
ClassLoader loader = contextCL == null ? ClassUtils.class.getClassLoader() : contextCL;

       My problem is that when I invoke the same routine using a WebSphere version 8 task Executor  (org.springframework.scheduling.commonj.WorkManagerTaskExecutor), I get a java.lang.ClassNotFoundException exception on those same classes specified within mapping.xml  that dozer finds okay when I invoke dozer by just clicking a button in a servlet..




Dmitry Buzdin

unread,
Mar 28, 2013, 4:26:04 PM3/28/13
to dozer-...@googlegroups.com
I would guess that it is not Dozer specific since ClassUtils approach is fairly standard and works on most environments except certain OSGi cases. This one is rather classloading issue.

What is your application structure (war, ear, jar) and what is the location of class calling Dozer Mapper and class referenced by mapping?

Could you access the same class by Class.forName without using Dozer from the same place?

Dmitry

четверг, 28 марта 2013 г., 20:52:57 UTC+2 пользователь Robert Glover Jr написал:

Robert Glover Jr

unread,
Apr 8, 2013, 7:54:56 AM4/8/13
to dozer-...@googlegroups.com
I fixed the problem using as the basis the information in this post:  https://github.com/DozerMapper/dozer/issues/22
Here is the Spring configuration:

<bean id="dataDefinitionConverter"    class="foo.bar.baz.intake.dtf.parser.DataDefinitionConverter" >
        <property name="mapper"    ref="smtsDozerBeanmapper" />
    </bean>
   
    <!-- see: http://dozer.sourceforge.net/documentation/springintegration.html -->
   
    <bean id="dozerBeanmapper"    class="org.dozer.DozerBeanMapper" >
        <property name="mappingFiles">
            <list>
                  <value>foo/bar/baz/intake/dtf/conversion/mappings.xml</value>
            </list>
          </property>
    </bean>
        <!--
           The idea that inspired creation of this class is this article on the web:
           https://github.com/DozerMapper/dozer/issues/22
         -->
        <bean id="smtsDozerBeanmapper"    class="foo.bar.baz.intake.dozer.SmtsDozerBeanMapper" >
        <property name="targetMapper"    ref="dozerBeanmapper" />
    </bean>

And here the overridden map method:

@Override
    public <T> T map(Object source, Class<T> destinationClass)
            throws MappingException {
        ClassLoader originalContextClassLoader = Thread.currentThread().getContextClassLoader();
        ClassLoader classClassLoader = DataDefinition.class.getClassLoader();
        if (firstTime) {
            firstTime = false;
            logger.info("DataDefinition.class.getClassLoader()=: "+  classClassLoader);
            logger.info("Thread.currentThread().getContextClassLoader()=: "+  originalContextClassLoader);
        }
        if (logger.isDebugEnabled()) {
            logger.debug("DataDefinition.class.getClassLoader()=: "+  classClassLoader);
            logger.debug("Thread.currentThread().getContextClassLoader()=: "+  originalContextClassLoader);
        }
        if (null!=classClassLoader)  {
            Thread.currentThread().setContextClassLoader(classClassLoader);
        } else {
            logger.warn("Thread.currentThread().getContextClassLoader() returned null");
        }
        try {
            return this.getTargetMapper().map( source,  destinationClass);
        } finally {
            Thread.currentThread().setContextClassLoader(originalContextClassLoader);
Reply all
Reply to author
Forward
0 new messages