markbug
2015-12-12 04:48
采纳率: 77.8%
浏览 10.4k
已采纳

Spring配置文件中DOCTYPE与<beans xmlns>冲突问题

这是DOCTYPE

<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd:/spring-beans.dtd">

这是beans里的配置
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

报错信息:

Multiple annotations found at this line:

  • The content of element type "beans" must match "(description?,(import|alias| bean)*)".
  • Attribute "xsi:schemaLocation" must be declared for element type "beans".
  • Attribute "xmlns:xsi" must be declared for element type "beans".
  • Attribute "xmlns" must be declared for element type "beans".
  • Attribute "xmlns:tx" must be declared for element type "beans".
  • Attribute "xmlns:aop" must be declared for element type "beans".

求大神,

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

5条回答 默认 最新

  • markbug 2015-12-12 06:05
    已采纳

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

    <beans  xmlns="http://www.springframework.org/schema/beans"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            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/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">
                <!-- Spring AOP 日志管理 -->
    <!-- 将日志类注入到bean中 -->
    <bean id="advices" class="advice.Advices"></bean>
    
    <aop:config>
        <!-- 调用日志类 -->
        <aop:aspect id="advice" ref="advices">
            <aop:pointcut expression="execution(* action.*.*(..))" id="log"/>
            <aop:before method="before" pointcut-ref="log"/>
            <aop:after method="afterReturning" pointcut-ref="log"/>
            <aop:after-throwing method="afterThrowing" pointcut-ref="log"/>
        </aop:aspect>
    
    </aop:config>
    

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • kevin-go 2015-12-12 04:56

    可以直接去掉DOCTYPE试试
    这是我项目中的某个spring配置文件

     <?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:aop="http://www.springframework.org/schema/aop" 
        xmlns:tx="http://www.springframework.org/schema/tx" 
        xmlns:context="http://www.springframework.org/schema/context" 
        xmlns:p="http://www.springframework.org/schema/p" 
        xsi:schemaLocation="  
                http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-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  
                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"  
                default-autowire="byName" default-lazy-init="false"> 
    </beans>
    
    评论
    解决 1 无用
    打赏 举报
  • markbug 2015-12-12 05:30

    用import 导入到applicationContext.xml中也不行的

    评论
    解决 无用
    打赏 举报
  • kevin-go 2015-12-12 06:01

    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

    xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    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-2.5.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

    注意:必须加上 xmlns="http://www.springframework.org/schema/beans"

    另:<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> 去掉里面的冒号试试

    评论
    解决 无用
    打赏 举报
  • markbug 2015-12-12 06:08

    Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
    org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from relative location [xml/spring-advice.xml]
    Offending resource: ServletContext resource [/WEB-INF/classes/applicationContext.xml]; nested exception is org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 11 in XML document from ServletContext resource [/WEB-INF/classes/xml/spring-advice.xml] is invalid; nested exception is org.xml.sax.SAXParseException: Attribute "xmlns" must be declared for element type "beans".
    Caused by: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 11 in XML document from ServletContext resource [/WEB-INF/classes/xml/spring-advice.xml] is invalid; nested exception is org.xml.sax.SAXParseException: Attribute "xmlns" must be declared for element type "beans".
    Caused by: org.xml.sax.SAXParseException: Attribute "xmlns" must be declared for element type "beans".

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题