Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
zuihou opened this issue Sep 7, 2018 · 14 comments

Comments

@zuihou
Copy link

zuihou commented Sep 7, 2018

Springcloud projects start error reporting.

Whats your runtime?

  • Dozer version: 6.4.0_
  • OS version: __mac os 10.13.4 ___
  • JDK version: 8_
  • SpringBoot version: 2.0.0.RELEASE
  • SpringCloud version: Finchley.M8

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
Copy link
Collaborator

@garethahealy
Copy link
Collaborator

@garethahealy
Copy link
Collaborator

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

@tryIdea
Copy link

tryIdea commented Oct 22, 2018

I also have the problem.why

@garethahealy
Copy link
Collaborator

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

@tryIdea
Copy link

tryIdea commented Dec 6, 2018

@garethahealy github repo: dozer-test

@garethahealy
Copy link
Collaborator

@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
Copy link

tryIdea commented Dec 7, 2018

@garethahealy Code has been updated

@xrogzu
Copy link

xrogzu commented Dec 10, 2018

@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
Copy link

ulquio commented Jan 17, 2019

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
Copy link
Author

zuihou commented Jan 27, 2019

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:
- classpath:dozer/global.dozer.xml # ok
- classpath:dozer/xxx.dozer.xml # ok
#mappingFiles: classpath*:dozer/*.dozer.xml # cannot use *

@garethahealy
Copy link
Collaborator

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

@kazuki43zoo
Copy link
Contributor

@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
Copy link

wjn0918 commented May 13, 2020

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>

</beans>
  1. config your application.yml
server:
  port: 80

spring:
  config:
    location: classpath:applicationContext.xml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants