Java Spring工具套件应用程序上下文xml错误,即使所有bean似乎都正常工作

Java Spring工具套件应用程序上下文xml错误,即使所有bean似乎都正常工作,java,xml,spring,Java,Xml,Spring,我正在一个spring应用上下文XML中配置jpa和jpa存储库 如果我同时拥有和,那么Spring工具套件在第1行显示一个错误: 引用的文件包含错误(http://www.springframework.org/schema/context/spring-context-4.0.xsd). 有关详细信息,请右键单击中的消息 查看问题并选择“显示详细信息…” 单击“显示详细信息”后,我得到以下信息: The errors below were detected when validating t

我正在一个spring应用上下文XML中配置jpa和jpa存储库

如果我同时拥有
,那么Spring工具套件在第1行显示一个错误:

引用的文件包含错误(http://www.springframework.org/schema/context/spring-context-4.0.xsd). 有关详细信息,请右键单击中的消息
查看问题并选择“显示详细信息…”

单击“显示详细信息”后,我得到以下信息:

The errors below were detected when validating the file "spring-context-4.0.xsd" viathe file "app-config.xml".  In most cases these errors can be detected by validating "spring-context-4.0.xsd" directly.  However it is possible that errors will only occur when spring-context-4.0.xsd is validated in the context of app-config.xml.

sch-props-correct.2: A schema cannot contain two global components with the same name; this schema contains two occurrences of 'http://www.springframework.org/schema/context,propertyPlaceholder'.  line 22

sch-props-correct.2: A schema cannot contain two global components with the same name; this schema contains two occurrences of 'http://www.springframework.org/schema/context,property-placeholder'.  line 91

sch-props-correct.2: A schema cannot contain two global components with the same name; this schema contains two occurrences of 'http://www.springframework.org/schema/context,property-override'.  line 155

sch-props-correct.2: A schema cannot contain two global components with the same name; this schema contains two occurrences of 'http://www.springframework.org/schema/context,annotation.config'.  line 174

sch-props-correct.2: A schema cannot contain two global components with the same name; this schema contains two occurrences of 'http://www.springframework.org/schema/context,component-scan'.  line 194

sch-props-correct.2: A schema cannot contain two global components with the same name; this schema contains two occurrences of 'http://www.springframework.org/schema/context,load-time-weaver'.  line 315

sch-props-correct.2: A schema cannot contain two global components with the same name; this schema contains two occurrences of 'http://www.springframework.org/schema/context,spring-configured'.  line 392

sch-props-correct.2: A schema cannot contain two global components with the same name; this schema contains two occurrences of 'http://www.springframework.org/schema/context,mbean-export'.  line 405

sch-props-correct.2: A schema cannot contain two global components with the same name; this schema contains two occurrences of 'http://www.springframework.org/schema/context,mbean-server'.  line 458

sch-props-correct.2: A schema cannot contain two global components with the same name; this schema contains two occurrences of 'http://www.springframework.org/schema/context,filterType'.  line 488
旁边有一条警告说
未找到引用的bean“jpamappingcontext”

运行应用程序时,它似乎工作正常。我可以连接到数据库,并使用JpaRepository接口从数据库中获取数据,因此我不确定为什么STS中会出现致命错误。我假设,由于jpa:repositories和context:component扫描包都使用了这两种扫描包,所以在使用这两种扫描包时会出现一些重复/冲突,但我不确定应该如何解决它(我可能会将服务拆分为它们自己的配置xml,然后在app config中导入,或者将其添加到web.xml中的上下文列表中)

以下是完整的app-config.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:tx="http://www.springframework.org/schema/tx"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:util="http://www.springframework.org/schema/util"
    xmlns:jpa="http://www.springframework.org/schema/data/jpa"
    xmlns:context="http://www.springframework.org/schema/context"
    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-4.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-4.0.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">

    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"
    p:driverClassName="org.h2.Driver"
    p:url="jdbc:h2:tcp://localhost/~/test;INIT=CREATE SCHEMA IF NOT EXISTS TEST"
    p:username="sa"
    p:password="" />

    <bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" 
    p:showSql="true" />

    <util:map id="jpaProperties">
        <entry key="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
        <entry key="hibernate.hbm2ddl.auto" value="update" />
        <entry key="hibernate.default_schema" value="test" />
    </util:map>

    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
    p:dataSource-ref="dataSource"
    p:packagesToScan="hr.mrplow.test.model"
    p:jpaVendorAdapter-ref="jpaVendorAdapter"
    p:jpaProperties-ref="jpaProperties" />  

    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"
    p:entityManagerFactory-ref="entityManagerFactory"
    p:rollbackOnCommitFailure="true" />

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

    <jpa:repositories base-package="hr.mrplow.test.DAO" />

    <!-- Services -->
    <context:component-scan base-package="hr.mrplow.test.service" />
</beans>


以下是完整的app config.xml

这是STS中的一个已知问题:

虽然这个问题已经被宣布关闭,但你可以看到它仍然会弹出


你应该考虑用你的箱子打开一张有春天的JIRA票。

我相信你两次都包括同一个部件。你能保证最多包含一次吗?嗯,我正在对两个不同的包进行包扫描,两个包中都没有重复的类。在DAO包中,我有一个JpaRepository接口,在服务包中,我有一个自动连接DAO的服务接口和实现。消息表明
spring-context-4.0.xsd中有一个错误,重复行号高达488,远高于您的文件长度。您使用的是哪一版本的spring framework和spring jpa?@SergeBallesta 4.0.5.RELEASE。因此,目前,我是否应该忽略这些错误?我能认为它们无害吗?应用程序确实可以工作,但我通常不喜欢应用程序中出现错误。目前,我的“解决方法”是将存储库和服务包扫描仪分离为两个.xml文件,并将它们导入到我的app-config.xml中。这就消除了errors@MrPlow我知道看到红旗潜伏在拐角处很烦人。但只要应用程序运行正常,就应该可以了。你可以再尝试一件事来移除XSD的版本,看看。我会贴一张票,我会玩它,但是就这个帖子来说,我认为我的问题得到了解答。非常感谢。