首页 文章

无法找到XML架构命名空间的Spring NamespaceHandler [http://www.springframework.org/schema/data/jpa]

提问于
浏览
7

任何想法,什么可能导致此错误?

org.springframework.beans.factory.parsing.BeanDefinitionParsingException:配置问题:无法找到XML架构命名空间的Spring NamespaceHandler [http://www.springframework.org/schema/data/jpa]攻击资源:ServletContext资源[/ WEB -INF / spring / appServlet / servlet的context.xml中]

这是我的'servle-context.xml'(缩进有一些问题,但文件太大了......):

<?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>

如您所见,我指定了jpa-schema的路径 . 我不知道是什么问题

7 回答

  • 2

    尝试更换

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

    通过

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

    但是,如果您仍然使用版本1.0-M1,请先尝试更新 . DATAJPA-21

  • 0

    确保您的依赖项中有spring-data-jpa

    如果你使用maven:

    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-jpa</artifactId>
        <version>1.7.0.RELEASE</version>
    </dependency>
    
  • 0

    我通过解决项目中缺少spring-tx依赖项来解决这个问题 .

    org.springframework: Spring 天-TX

  • 1

    问题是因为无法找到spring-jpa架构 . 您可能正在使用一些不包含架构信息的旧jar .

  • 3

    我知道这看起来很傻,但是如果你使用的是IDEA和Maven,你应该检查以确保你已经检查了使用插件注册表,这样服务器也可以访问你的jar文件 .

    我会发布一个屏幕截图,但我是新来的,没有足够的声望点 . 它确实有效,我已经与IntelliJ的支持团队进行了验证

  • 0

    在一周内遇到同样的问题后,我找到了解决方案 . 如果您使用的是Spring MVC JPA Maven,请使用此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>
    
  • 0

    为时已晚,但这解决了我的问题:

    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-jpa</artifactId>
        <version>1.9.4.RELEASE</version>
    </dependency>
    

相关问题