class not found exception in Dozer

3.1k views Asked by At

I am trying to execute below dozer example. my class file is inside classes folder, but i am getting the class not found exception.

org.dozer.MappingException: java.lang.ClassNotFoundException: portal.control.profile.ChangeProfileRequest
        at org.dozer.util.MappingUtils.throwMappingException(MappingUtils.java:82) ~[dozer-5.5.1.jar:na]
        at org.dozer.util.DefaultClassLoader.loadClass(DefaultClassLoader.java:43) ~[dozer-5.5.1.jar:na]
        at org.dozer.util.MappingUtils.loadClass(MappingUtils.java:224) ~[dozer-5.5.1.jar:na]
        at org.dozer.loader.DozerBuilder$MappingBuilder.classA(DozerBuilder.java:129) ~[dozer-5.5.1.jar:na]
        at org.dozer.loader.xml.XMLParser.parseMapping(XMLParser.java:190) ~[dozer-5.5.1.jar:na]
        at org.dozer.loader.xml.XMLParser.read(XMLParser.java:137) ~[dozer-5.5.1.jar:na]
        at org.dozer.loader.xml.XMLParser.read(XMLParser.java:43) ~[dozer-5.5.1.jar:na]
        at org.dozer.loader.xml.MappingStreamReader.read(MappingStreamReader.java:51) ~[dozer-5.5.1.jar:na]
        at org.dozer.loader.xml.MappingFileReader.read(MappingFileReader.java:58) [dozer-5.5.1.jar:na]
        at org.dozer.DozerBeanMapper.loadFromFiles(DozerBeanMapper.java:227) [dozer-5.5.1.jar:na]
        at org.dozer.DozerBeanMapper.loadCustomMappings(DozerBeanMapper.java:209) [dozer-5.5.1.jar:na]
        at org.dozer.DozerBeanMapper.initMappings(DozerBeanMapper.java:315) [dozer-5.5.1.jar:na]
        at org.dozer.DozerBeanMapper.getMappingProcessor(DozerBeanMapper.java:192) [dozer-5.5.1.jar:na]
        at org.dozer.DozerBeanMapper.map(DozerBeanMapper.java:120) [dozer-5.5.1.jar:na]
        at portal.control.profile.UpdateOrgDetailsCtrl.getOrgDetails(UpdateOrgDetailsCtrl.java:81) [UpdateOrgDetailsCtrl.class:na]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_67]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_67] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_67]
        at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_67]
        at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215) [spring-web-4.0.5.RELEASE.jar:4.0.5.RELEASE]
        at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132) [spring-web-4.0.5.RELEASE.jar:4.0.5.RELEASE]
        at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104) [spring-webmvc-4.0.5.RELEASE.jar:4.0.5.RELEASE]
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749) [spring-webmvc-4.0.5.RELEASE.jar:4.0.5.RELEASE]
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689) [spring-webmvc-4.0.5.RELEASE.jar:4.0.5.RELEASE]
        at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83) [spring-webmvc-4.0.5.RELEASE.jar:4.0.5.RELEASE]
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938) [spring-webmvc-4.0.5.RELEASE.jar:4.0.5.RELEASE]
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870) [spring-webmvc-4.0.5.RELEASE.jar:4.0.5.RELEASE]
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961) [spring-webmvc-4.0.5.RELEASE.jar:4.0.5.RELEASE]
        at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852) [spring-webmvc-4.0.5.RELEASE.jar:4.0.5.RELEASE]
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:618) [servlet-api.jar:na]
        at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837) [spring-webmvc-4.0.5.RELEASE.jar:4.0.5.RELEASE]
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:725) [servlet-api.jar:na]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291) [catalina.jar:8.0.14]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:8.0.14]
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) [tomcat-websocket.jar:8.0.14]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) [catalina.jar:8.0.14]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:8.0.14]
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219) [catalina.jar:8.0.14]
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) [catalina.jar:8.0.14]
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:506) [catalina.jar:8.0.14]
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142) [catalina.jar:8.0.14]
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) [catalina.jar:8.0.14]
        at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610) [catalina.jar:8.0.14]
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) [catalina.jar:8.0.14]
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:537) [catalina.jar:8.0.14]
        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1081) [tomcat-coyote.jar:8.0.14]
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:658) [tomcat-coyote.jar:8.0.14]
        at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222) [tomcat-coyote.jar:8.0.14]
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1566) [tomcat-coyote.jar:8.0.14]
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1523) [tomcat-coyote.jar:8.0.14]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [na:1.7.0_67]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [na:1.7.0_67]
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-util.jar:8.0.14]
        at java.lang.Thread.run(Thread.java:745) [na:1.7.0_67]
Caused by: java.lang.ClassNotFoundException: portal.control.profile.ChangeProfileRequest
        at java.net.URLClassLoader$1.run(URLClassLoader.java:366) ~[na:1.7.0_67]
        at java.net.URLClassLoader$1.run(URLClassLoader.java:355) ~[na:1.7.0_67]
        at java.security.AccessController.doPrivileged(Native Method) ~[na:1.7.0_67]
        at java.net.URLClassLoader.findClass(URLClassLoader.java:354) ~[na:1.7.0_67]
        at java.lang.ClassLoader.loadClass(ClassLoader.java:425) ~[na:1.7.0_67]
        at java.lang.ClassLoader.loadClass(ClassLoader.java:358) ~[na:1.7.0_67]
        at java.lang.Class.forName0(Native Method) ~[na:1.7.0_67]
        at java.lang.Class.forName(Class.java:270) ~[na:1.7.0_67]
        at org.apache.commons.lang3.ClassUtils.getClass(ClassUtils.java:828) ~[commons-lang3-3.3.2.jar:3.3.2]
        at org.apache.commons.lang3.ClassUtils.getClass(ClassUtils.java:862) ~[commons-lang3-3.3.2.jar:3.3.2]
        at org.dozer.util.DefaultClassLoader.loadClass(DefaultClassLoader.java:41) ~[dozer-5.5.1.jar:na]
        ... 52 common frames omitted

Dozer Configuration:

<mapping>
    <class-a>portal.control.profile.ChangeProfileRequest</class-a>
    <class-b>store.sa.profile.SaProfile</class-b>
    <field>
        <a>profileType</a>
        <b>type</b>
    </field>
</mapping>

in PortalConfiguration class

@EnableWebMvc
@EnableAsync
public class PortalConfiguration extends WebMvcConfigurerAdapter implements AsyncConfigurer {
  ....
  @Bean
  public DozerBeanMapper mapper(){
     DozerBeanMapper mapper = new DozerBeanMapper();
     List<String> mappingFilesUrls = new ArrayList<>();
     mappingFilesUrls.add("dozer/dozer-bean-mappings.xml");
     mapper.setMappingFiles(mappingFilesUrls);
     return mapper;
  }
  ......
}

My Java Code:

ChangeProfileRequest profileRequest = new ChangeProfileRequest();
try {
    profileRequest = mapper.map(saProfile, ChangeProfileRequest.class);
} catch (Exception e) {
    LOGGER.error(e.getMessage(), e);
}

ChangeProfileRequest is exist in classes folder. Same class when put inside the jar it is working.. image shown below,

enter image description here

0

There are 0 answers