org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException 在春天

Posted

技术标签:

【中文标题】org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException 在春天【英文标题】:org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException in spring 【发布时间】:2014-02-26 19:23:16 【问题描述】:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemalocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">


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


<context:component-scan base-package="com.dineshonjava" />
<tx:annotation-driven transaction-manager="hibernateTransactionManager" />


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

<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="sessionFactory"
    class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">

    <property name="dataSource">
        <ref bean="dataSource" />
    </property>

    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.mysqlDialect</prop>
            <prop key="hibernate.show_sql">true</prop>
        </props>
    </property>

    <property name="annotatedClasses">
        <list>
            <value>com.dineshonjava.model.Employee</value>
        </list>
    </property>
</bean>

<bean class="org.springframework.orm.hibernate3.HibernateTransactionManager"
    id="hibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory"></property>
</bean>
</beans>  

我是春天的新人。我有 org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException:来自 ServletContext 资源 [/WEB-INF/config/sdnext-servlet.xml] 的 XML 文档中的第 8 行无效;嵌套异常是 org.xml.sax.SAXParseException;行号:8;列号:120; cvc-elt.1:找不到元素“bean”的声明。在 spring 配置文件中。提前致谢。

【问题讨论】:

您有pom.xml 文件吗?如果可以的话可以发一下吗? 不,我没有使用 maven 【参考方案1】:

配置似乎缺少结束 &lt;/beans&gt; 标记。

还可以尝试指定 bean 架构的版本:

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/context-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">

</beans>

【讨论】:

【参考方案2】:

你的 beans 开始标签是错误的,替换为;它适用于我在 spring 3.0 检查架构位置:

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:wss="http://jax-ws.dev.java.net/spring/servlet"
    xmlns:ws="http://jax-ws.dev.java.net/spring/core" xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jee="http://www.springframework.org/schema/jee"
    xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
       http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-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/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

【讨论】:

【参考方案3】:

我认为您的架构位置无效。所以请把spring配置文件中的xsi:schemalocation改为xsi:schemaLocation。

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"     xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">

..........

</beans>

【讨论】:

这帮助我解决了复数视力教程的问题,谢谢。【参考方案4】:

用下面的代码替换标签。它对我有用:

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
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-3.2.xsd">

【讨论】:

以上是关于org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException 在春天的主要内容,如果未能解决你的问题,请参考以下文章

REST API:org.springframework.beans.factory.UnsatisfiedDependencyException:

Spring security-org.springframework.beans.factory.BeanCreationException:创建名为“org.springframework.sec

org.springframework.beans.factory.UnsatisfiedDependencyException:

没有实现 [org.springframework.beans.factory.xml.NamespaceHandler] 接口

Spring Boot 错误 org.springframework.beans.factory.UnsatisfiedDependencyException

org.springframework.beans.factory.UnsatisfiedDependencyException:创建 bean 时出错