2017-04-26 1378 views
0

我是springMVC的新手。使用springMVC 4.2.4,Tomacat 9.0,Maven 4.0,Java 1.8,Eclipse IDE,當我嘗試在bean中寫入一個bean時,它顯示一個錯誤。以下是配置xml文件。我在xml中創建bean時出現以下錯誤** cvc-complex-type.2.4.a:發現以元素'bean'開頭的無效內容**

<?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:context="http://www.springframework.org/schema/context" 
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xmlns:p="http://www.springframework.org/schema/p" 
    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"> 

<mvc:annotation-driven /> 

<mvc:resources location="pdfs" mapping="/pdfs/**" /> 


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

<mvc:interceptors> 
    <bean 
    class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" 
     p:paramName="language" /> 
</mvc:interceptors> 

<bean 

class= 
    "org.springframework.web.servlet.view.ContentNegotiatingViewResolver"> 
    <property name="order" value="1" /> 
    <property name="ContentNegotiationManager" /> 
    **<bean** 
    class="org.springframework.web.accept.ContentNegotiationManager"> 
     <constructor-arg> 
      <bean 

    class="org.springframework. 
    web.accept.PathExtensionContentNegotiationStrategy"> 
       <constructor-arg> 
        <map> 
         <entry key="json" value="application/json" /> 
         <entry key="xml" value="application/xml" /> 
        </map> 
       </constructor-arg> 
      </bean> 
     </constructor-arg> 
    </bean> 
    <property name="defaultViews"> 
     <list> 
      <bean 

    class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" 
    /> 
      <bean 
    class="org.springframework.wweb.servlet.view.xml.MarshallingView"> 
       <constructor-arg> 
        <bean 
    class="org.springframework.oxm.xstream.XStreamMarshaller"> 
         <property name="autodetectAnnotations" value="true" 
    /> 
        </bean> 
       </constructor-arg> 
      </bean> 
     </list> 
    </property> 
</bean> 
</beans> 
+0

可以請你分享你看到完整的錯誤 – ScanQR

回答

0

的錯誤是在這裏:

<?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:context="http://www.springframework.org/schema/context" 
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xmlns:p="http://www.springframework.org/schema/p" 
    xsi:schemaLocation="http://www.springframework.org/schema/mvc 

您不包括bean命名空間。所以要解決這個問題,請添加它。這裏有一個例子(來自我的項目)。

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

然後實例化一個新的bean:

<beans:bean id="...." class="......"/> 
相關問題