7

Any ideas, what could cause this error?

org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/data/jpa] Offending resource: ServletContext resource [/WEB-INF/spring/appServlet/servlet-context.xml]

Here is my 'servle-context.xml' (there are some problems with the indents, but the file is too huge...):

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

<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->

<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven />

<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />

<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <beans:property name="prefix" value="/WEB-INF/views/" />
    <beans:property name="suffix" value=".jsp" />
</beans:bean>

<context:component-scan base-package="com.epam.mvc3.model" />
<context:component-scan base-package="com.epam.mvc3.controller" />

<!-- JPA -->
<beans:bean
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <beans:property name="location">
        <beans:value>resources/database.properties</beans:value>
    </beans:property>
</beans:bean>

<beans:bean id="myDataSource"
    class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <beans:property name="driverClassName">
        <beans:value>${jdbc.driverClassName}</beans:value>
    </beans:property>
    <beans:property name="url">
        <beans:value>${jdbc.url}</beans:value>
    </beans:property>
    <beans:property name="username">
        <beans:value>${jdbc.username}</beans:value>
    </beans:property>
    <beans:property name="password">
        <beans:value>${jdbc.password}</beans:value>
    </beans:property>
</beans:bean>

<beans:bean id="myEmf"
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <beans:property name="dataSource" ref="myDataSource" />

    <beans:property name="persistenceUnitName" value="application" />
    <beans:property name="persistenceXmlLocation"
        value="classpath*:META-INF/persistence.xml" />
    <beans:property name="jpaVendorAdapter" ref="hibernateVendor" />

    <beans:property name="loadTimeWeaver">
        <beans:bean
            class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"></beans:bean>
    </beans:property>
</beans:bean>

<beans:bean id="hibernateVendor"
    class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
</beans:bean>

<beans:bean id="transactionManager"
    class="org.springframework.orm.jpa.JpaTransactionManager">
    <beans:property name="entityManagerFactory" ref="myEmf"></beans:property>
</beans:bean>

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

<!-- Spring Data configuration -->
<jpa:repositories base-package="com.epam.mvc3.repository"/>

</beans:beans>

As you can see, i specified the path to the jpa-schema. And I don't know what is the problem

Eugene
  • 5,353
  • 6
  • 27
  • 37

7 Answers7

3

Try to replace

http://www.springframework.org/schema/data/jpa/spring-jpa.xsd

by

http://www.springframework.org/schema/data/jpa/spring-jpa-1.0.xsd

But if you still use Version 1.0-M1 then try to update first. DATAJPA-21

Ralph
  • 118,862
  • 56
  • 287
  • 383
  • Although this is the acceptable answer it did not solve this issue for me. I using spring-data-jpa 1.2.0.RELEASE and the rest of my spring jars are 3.1.3.RELEASE. Regarding spring-data-commons-core - I don't even have a dependency in my pom but I can see it in my m2 repository along with spring-data-commons-parent and both of version 1.4.0.RELEASE, I don't know why (maybe those are part of spring-data-jpa?). Any new insights? – forhas Dec 05 '12 at 07:20
  • @forhas: this seams to be a different question. So create a new Stack Overflow question (Descripe your Probelem, configuration and Exception, as well as what you have tryed so fare) and maybe leave a link to you question here as an comment. – Ralph Dec 05 '12 at 07:27
2

Make sure you have spring-data-jpa in your dependencies

If you use maven:

<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-jpa</artifactId>
    <version>1.7.0.RELEASE</version>
</dependency>
Alex B
  • 1,866
  • 22
  • 17
1

I fixed this by resolving the missing the spring-tx dependency in our project.

org.springframework:spring-tx

nrkkalyan
  • 179
  • 2
  • 5
0

I know this seems silly, but if you are using IDEA and Maven you should check to make sure you have Use plugin registry checked so that the server also has access to your jar files.

I would post a screen shot but I'm new on here and don't have enough reputation points. It does work though and I've verified with the support team at IntelliJ

user3264641
  • 71
  • 1
  • 4
0

After facing this same problem over a week, I found a solution. If you are using Spring MVC + JPA + Maven, use this dispatcher-servlet.xml

<?xml version="1.0" encoding="windows-1252"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context.xsd
       http://www.springframework.org/schema/mvc
       http://www.springframework.org/schema/mvc/spring-mvc.xsd
       http://www.springframework.org/schema/aop
       http://www.springframework.org/schema/aop/spring-aop.xsd
       http://www.springframework.org/schema/tx
       http://www.springframework.org/schema/tx/spring-tx.xsd">

    <!-- Use @Component annotations for bean definitions -->
    <context:component-scan base-package="PACKAGE WHERE YOU CAN FIND YOUR SOURCE CODE"/>

    <!-- Use @Controller annotations for MVC controller definitions -->
    <mvc:annotation-driven />

    <!-- Add JPA support -->
    <bean id="emf" class=
            "org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="loadTimeWeaver">
            <bean class=
                          "org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/>
        </property>
    </bean>

    <!-- Add Transaction support -->
    <bean id="transactionManager"
          class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="emf"/>
    </bean>

    <!-- Use @Transaction annotations for managing transactions -->
    <tx:annotation-driven transaction-manager="transactionManager" />

    <!-- View resolver -->
    <bean class=

<!-- HERE YOU REPLACE PROPERTY VALUE TO MATCH YOUR VIEW FOLDER (JSP PAGES) -->
                  "org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/web/"/> 
        <property name="suffix" value=".jsp"/>
    </bean>

</beans>
Victor Viola
  • 575
  • 1
  • 4
  • 14
0

too late, but this solved my problem:

<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-jpa</artifactId>
    <version>1.9.4.RELEASE</version>
</dependency>
Alejandro
  • 766
  • 9
  • 24
0

The issue is because the spring-jpa schema cannot be located . You might be having some old jar which does not contain the schema info .

Aravind A
  • 9,507
  • 4
  • 36
  • 45
  • I'm using the "hibernate-core-3.6.3.Final.jar", "hibernate-jpa-2.0-api-1.0.0.Final.jar", "spring-data-commons-core-1.1.0.RELEASE.jar", "spring-orm-3.0.5.RELEASE.jar". Do you think, that they are obsolete? – Eugene Jan 09 '12 at 10:51
  • @Eugene you are using the spring-jpa namespace - Don't you have the spring-jpa jar ? You may find it [here](http://mirrors.ibiblio.org/pub/mirrors/maven2/org/springframework/spring-jpa/) . – Aravind A Jan 09 '12 at 11:26