【问题标题】:Spring config xml isn't valid after adding spring-data-jpa schema references添加 spring-data-jpa 模式引用后,Spring config xml 无效
【发布时间】:2015-04-26 22:26:37
【问题描述】:

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

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不再有效?

弹簧配置.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>

【问题讨论】:

    标签: java xml spring spring-data spring-data-jpa


    【解决方案1】:

    请重新排序以下行:

    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
    

    这正是您的错误消息指向的位置,成对的外观 (namespace location) 是 relevant

    【讨论】:

      猜你喜欢
      • 2015-07-14
      • 2011-12-19
      • 2021-02-09
      • 2018-11-24
      • 2019-01-27
      • 2012-06-29
      • 1970-01-01
      • 2019-01-27
      • 2017-02-18
      相关资源
      最近更新 更多