user2180794
user2180794

Reputation: 1455

spring data - jpa application-context schema error

I am having an issue with the xml schema for spring jpa repository.

I have tried all the suggestions available online but do not seem to resolve it.

please help.

getting this error in the application-context.xml for the repository.

Multiple annotations found at this line:
- cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'repository:repositories'.
- cvc-complex-type.2.4.a: Invalid content was found starting with element 'repositories'. One of '{"http://www.springframework.org/schema/
beans":import, "http://www.springframework.org/schema/beans":alias, "http://www.springframework.org/schema/beans":bean, WC[##other:"http://
www.springframework.org/schema/beans"]}' is expected.

my application context looks like this

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jdbc="http://www.springframework.org/schema/jdbc"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:repository="http://www.springframework.org/schema/data/repository"
    xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
        http://www.springframework.org/schema/data/repository http://www.springframework.org/schema/data/repository/spring-repository-1.7.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <jdbc:embedded-database id="dataSource" type="H2" />

    <tx:annotation-driven transaction-manager="transactionManager" />

    <repositories base-package="com.company.repositories" />

    <context:component-scan base-package="com.company.*" />
</beans>

Upvotes: 0

Views: 1276

Answers (2)

Oliver Drotbohm
Oliver Drotbohm

Reputation: 83121

We generally recommend to refer to the schema files that don't have version numbers in them as this will make sure you pick up the version form the dependency in your classpath.

The reason for this is that XSD doesn't know any kind of version concept. This means that spring-beans.xsd and spring-beans-3.0.xsd are completely unrelated to XSD which in turn means that if you happen to import both of them (I'll get to that in a second), this will create errors as XSD considers the types declared in them to be declared twice.

The reason you might accidentally import a non-versioned XSD is that the Spring Data XSDs actually refer to them to make sure we pick up the latest version (to be forward compatible).

Long story short: remove the explicit versions from the names and you should be good.

Upvotes: 1

user2180794
user2180794

Reputation: 1455

after a lot of trial and error the following application context doesn't seem to have any errors.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jdbc="http://www.springframework.org/schema/jdbc"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:jpa="http://www.springframework.org/schema/data/jpa"
    xmlns:repository="http://www.springframework.org/schema/data/repository"
    xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
        http://www.springframework.org/schema/data/repository http://www.springframework.org/schema/data/repository/spring-repository-1.7.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <jdbc:embedded-database id="dataSource" type="H2" />

    <tx:annotation-driven transaction-manager="transactionManager" />

    <jpa:repositories base-package="com.company.repositories" />

    <context:component-scan base-package="com.company.*" />
</beans>

It beyond me why it didn't resolve the errors when I tried it earlier.

I was getting the following error.

Referenced file contains errors (http://www.springframework.org/schema/beans/spring-beans-3.0.xsd).

I did the following, preferences > general > network connection > cache --> deleted the caches xsd.

Then I clicked on the problems view and deleted the problem and cleaned the project. Don't have the error now. Anybody who understands this better is welcome to answer.

Upvotes: 0

Related Questions