DozerMapper / dozer

Dozer is a Java Bean to Java Bean mapper that recursively copies data from one object to another.
https://dozermapper.github.io/
Apache License 2.0
2.08k stars 481 forks source link

FileNotFoundException: ServletContext resource [/classpath*:dozer/*dozer.xml] cannot be resolved to URL because it does not exist #702

Closed zuihou closed 4 years ago

zuihou commented 6 years ago

Springcloud projects start error reporting.

Whats your runtime?

Whats the problem?

1, pom

        <dependency>
            <groupId>com.github.dozermapper</groupId>
            <artifactId>dozer-core</artifactId>
            <version>6.4.0</version>
        </dependency>
        <dependency>
            <groupId>com.github.dozermapper</groupId>
            <artifactId>dozer-spring-boot-starter</artifactId>
            <version>6.4.0</version>
        </dependency>

2 application.yml,

dozer:
  mappingFiles: classpath*:dozer/*.dozer.xml

3, mapping file :

 src/main/resources/dozer/global.dozer.xml

Observed Results:

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.github.dozermapper.spring.DozerBeanMapperFactoryBean]: Factory method 'dozerMapper' threw exception; nested exception is java.io.FileNotFoundException: ServletContext resource [/classpath*:dozer/*dozer.xml] cannot be resolved to URL because it does not exist
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:579)
    ... 45 common frames omitted
Caused by: java.io.FileNotFoundException: ServletContext resource [/classpath*:dozer/*dozer.xml] cannot be resolved to URL because it does not exist
    at org.springframework.web.context.support.ServletContextResource.getURL(ServletContextResource.java:174)
    at com.github.dozermapper.spring.DozerBeanMapperFactoryBean.setMappingFiles(DozerBeanMapperFactoryBean.java:81)
    at com.github.dozermapper.springboot.autoconfigure.DozerAutoConfiguration.dozerMapper(DozerAutoConfiguration.java:58)
    at com.github.dozermapper.springboot.autoconfigure.DozerAutoConfiguration$$EnhancerBySpringCGLIB$$c8b0337d.CGLIB$dozerMapper$0(<generated>)
    at com.github.dozermapper.springboot.autoconfigure.DozerAutoConfiguration$$EnhancerBySpringCGLIB$$c8b0337d$$FastClassBySpringCGLIB$$2d9afb47.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:361)
    at com.github.dozermapper.springboot.autoconfigure.DozerAutoConfiguration$$EnhancerBySpringCGLIB$$c8b0337d.dozerMapper(<generated>)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
    ... 46 common frames omitted
garethahealy commented 6 years ago

The line that is throwing the error, is a spring class:

Not sure how its a dozer problem...

garethahealy commented 6 years ago

We also have tests using classpath lookup, which dont fail:

garethahealy commented 6 years ago

@zuihou ; if you still have this issue, please provide a github repo with a junit test showing the problem.

tryIdea commented 5 years ago

I also have the problem.why

garethahealy commented 5 years ago

@tryIdea ; as the comment above says, please provide a github repo with a junit test showing the issue.

tryIdea commented 5 years ago

@garethahealy github repo: dozer-test

garethahealy commented 5 years ago

@tryIdea ; i am unable to build your example. get the following error:

[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.1.1.RELEASE:repackage (repackage) on project dozer-test-domain: Execution repackage of goal org.springframework.boot:spring-boot-maven-plugin:2.1.1.RELEASE:repackage failed: Unable to find main class

tryIdea commented 5 years ago

@garethahealy Code has been updated

xrogzu commented 5 years ago

@garethahealy ServletContext resource cannot load "classpath*",the reson maybe the interface Resource of Resource[] mappingFiles,injected by springboot, now only support dozer.mappingFiles=classpath:dozer/global-configuration.xml,classpath:dozer/user-mapping.xml

ulquio commented 5 years ago

Hello Same problem here The path is correct but still got FileNotFoundException

@zuihou Did you find a solution please ? I am using spring boot as well

Thank you

zuihou commented 5 years ago

Hello Same problem here The path is correct but still got FileNotFoundException

@zuihou Did you find a solution please ? I am using spring boot as well

Thank you

dozer: mappingFiles:

garethahealy commented 5 years ago

@kazuki43zoo ; if you are able, can you have a look at this please

kazuki43zoo commented 5 years ago

@garethahealy @zuihou

I've investigated this behavior and I found that it occurred since Spring Boot 2.x (1.5.x work fine). I think this issue's cause belong the Spring Boot project. Hence I've created the spring-projects/spring-boot#15835.

wjn0918 commented 4 years ago

you can use this way to reduce it error

  1. create applicationContext.xml to assign where is your dozer xml location

    
    <?xml version="1.0" encoding="UTF-8"?>
    <!--
    Copyright 2005-2019 Dozer Project
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at
         http://www.apache.org/licenses/LICENSE-2.0
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
    -->
    <beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
    
    <bean id="implicitMapper" class="com.github.dozermapper.core.DozerBeanMapperBuilder" factory-method="buildDefault"/>
    
    <!-- Provided Spring Integration -->
    <bean id="byFactory" class="com.github.dozermapper.spring.DozerBeanMapperFactoryBean">
        <!--this value is your dozer xml -->
        <property name="mappingFiles" value="classpath*:dozer/*.xml"/>
    </bean>

2. config your application.yml

server: port: 80

spring: config: location: classpath:applicationContext.xml