Resource ServletContext resource does not exist

Cifer Ulquiorra

I'm working on a project (spring boot) and I have to convert xml file to Java classes using the maven jaxb2 plugin. I'm following this link: the classes are generated the problem is when I try to unmarshall the xml I had this error: Resource ServletContext resource [/xsd/MX_seev_031_001_05. xsd] does not exist this is my application.properties:

context.path =xml.swift.spring.com
schema.location= xsd/MX_seev_031_001_05.xsd

this my bean of config:

@Bean
public Jaxb2Marshaller createJaxb2Marshaller(@Value("${context.path}") final String contextPath,
        @Value("${schema.location}") final Resource schemaResource){

    Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
    marshaller.setContextPath(contextPath);
    marshaller.setSchema(schemaResource);


    Map<String, Object> properties = new HashMap<>();
    properties.put(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    marshaller.setMarshallerProperties(properties);

    return marshaller;

the xsd file is under src/main/resources/xsd and this is my pom.xml:

<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.12.1</version>
<executions>
    <execution>
        <id>add-source-for-demoapp</id>
        <goals>
            <goal>generate</goal>
        </goals>
        <configuration>
            <schemaDirectory>${project.basedir}/src/main/resources/xsd</schemaDirectory>
            <schemaIncludes>
                <include>*.xsd</include>
            </schemaIncludes>


            <!--  Other configuration options-->

        </configuration>
    </execution>
</executions>

what i'am missing?

thanks.

Ilker P

I had basically the same issue, when I started to use spring-boot-starter-data-rest in addition to spring-oxm (I also have spring-boot-starter-data-jpa) in my pom.xml.

The problem is with your 2nd auto injected argument; @Value("${schema.location}") final Resource schemaResource

So instead of

@Bean
public Jaxb2Marshaller createJaxb2Marshaller(@Value("${context.path}") final String contextPath, @Value("${schema.location}") final Resource schemaResource){
    //...
    marshaller.setSchema(schemaResource);
    //...
}

Do below;

@Bean
public Jaxb2Marshaller createJaxb2Marshaller(@Value("${context.path}") final String contextPath, @Value("${schema.location}") final String schemaLocation){
    //...
    Resource schemaResource = new ClassPathResource(schemaLocation);
    marshaller.setSchema(schemaResource);
    //...
}

Give it a try, it will work.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

ServletContext resource "/views/index.html" does not exist

'Resource' does not exist in current context

Resource Does Not exist in Namespace xamarin

Optaplanner - The Website resource does not exist

Could not open ServletContext resource

Spring batch: Input resource does not exist class path resource

libcocos2dx resource error: resource directory does not exist

Could not open ServletContext resource -- except there is no reference to the resource

wpf resource dictionary does not exist in namespace?

Cloudformation: The resource you requested does not exist

Should HTTP PUT create a resource if it does not exist?

Can PUT create a resource which does not exist?

The file "Resource id #11" does not exist

Optaplanner - The benchmarkConfigResource does not exist as a classpath resource in the classLoader

resource directory not found when it does exist

Parsing of XML ServletContext resource BeanDefinitionStoreException

Terraform complains parent resource does not exist even though exist

"Could not open ServletContext resource" in test context

Java accessing ServletContext from within restlet Resource

'terraform init' returns 404 'Resource Group not found' when it does exist

Rspec: How to use expect to receive with a resource which does not exist yet?

Payara micro error: In TLD scanning, the supplied resource file does not exist

azure blob storage getting error - the specified resource does not exist

Paypal API v2 response The specified resource does not exist

Intermittently getting 404 error, "Owner resource does not exist"

ant - how to get a zero resource count if the folder does not exist

Terraform - don't create resource if data source does not exist

The requested resource does not exist [error] in Salesforce. What is wrong with Salesforce?

Are there multiple reasons for Azure error: "The specified resource does not exist"?