添加 spring-data-jpa 架构引用后,Spring config xml 无效 [英] Spring config xml isn't valid after adding spring-data-jpa schema references

查看:36
本文介绍了添加 spring-data-jpa 架构引用后,Spring config xml 无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在启动 spring 上下文时出现以下异常:

I have the following Exception while starting the spring context:

java.lang.Exception: java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.apache.catalina.LifecycleException: org.xml.sax.SAXParseException; systemId: http://www.springframework.org/schema/data/jpa/; lineNumber: 1; columnNumber: 55; White spaces are required between publicId and systemId.

在我将 spring-data-jpa 添加到 spring config.xml 之前,一切正常.为什么 xml 不再有效?

Before I added the spring-data-jpa to the spring config.xml everything worked fine. Why isn't the xml not valid anymore?

弹簧配置.xml

<?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:p="http://www.springframework.org/schema/p" 
       xmlns:context="http://www.springframework.org/schema/context" 
       xmlns:aop="http://www.springframework.org/schema/aop" 
       xmlns:tx="http://www.springframework.org/schema/tx" 
       xmlns:jpa="http://www.springframework.org/schema/data/jpa"
       xsi:schemaLocation="http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-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/data/jpa
        http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
        http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

    <context:property-placeholder location="classpath:application.properties" />

    <context:component-scan base-package="com.example" />

    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix">
            <value>/WEB-INF/jsp/</value>
        </property>
        <property name="suffix">
            <value>.jsp</value>
        </property>
    </bean>

    <!-- set up JPA and transaction config -->
    <tx:annotation-driven transaction-manager="transactionManager" />

    <!-- spring data jpa with JpaRepository -->
    <jpa:repositories base-package="com.example.repositories" />

    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="${jdbc.driverClassName}" />
        <property name="url" value="${jdbc.url}"/>
        <property name="username" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}"/>    
    </bean>
    <bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
        <property name="showSql" value="${hibernate.show_sql:false}"/>
        <property name="generateDdl" value="true"/>
        <property name="database" value="MYSQL"/>
    </bean>
    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="jpaVendorAdapter" ref="jpaVendorAdapter"/>
        <!-- spring based scanning for entity classes-->
        <property name="packagesToScan" value="com.example.entities"/>
    </bean>

    <bean id="transactionManager"  class="org.springframework.orm.jpa.JpaTransactionManager" />
</beans>

推荐答案

请重新排列以下几行:

http://www.springframework.org/schema/tx
http://www.springframework.org/schema/data/jpa
http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
http://www.springframework.org/schema/tx/spring-tx-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

这正是您的错误消息指向的地方,成对的外观(命名空间位置)是 相关

This is exactly where your error message points at, and the pair-wise appearance (namespace location) is relevant!

这篇关于添加 spring-data-jpa 架构引用后,Spring config xml 无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆