2012-07-17 185 views
1

我正在構建一個基本的MVC應用程序,並且已經正確使用了所有的配置文件。但仍然應用程序不統計。這是下面的配置文件,春季應用程序啓動

web.xml中

<?xml version="1.0" encoding="UTF-8"?> 

<web-app> 
    <servlet> 
     <servlet-name>dispatcher</servlet-name> 
     <servlet-class>org.springframework.web.servlet.DispatcherServlet 
     </servlet-class> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 


    <servlet-mapping> 
    <servlet-name>dispatcher</servlet-name> 
    <url-pattern>/</url-pattern> 
    </servlet-mapping> 

    <welcome-file-list> 
      <welcome-file>jsp/index.jsp</welcome-file> 
    </welcome-file-list> 

</web-app> 

上下文配置

<?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.com/schema/context" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
          http://www.springframework.org/schema/beans/spring-beans-3.2.xsd 
          http://www.springframework.org/schema/context 
          http://www.springframework.org/schema/context/spring-context-3.2.xsd"> 

    <context:annotation-config /> 
    <context:component-scan base-package="controllers"> 
    </context:component-scan> 


    <bean id="viewResolver" 
     class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <property name="viewClass" 
      value="org.springframework.web.servlet.view.JstlView" /> 
     <property name="prefix" value="/jsp/" /> 
     <property name="suffix" value=".jsp" /> 
    </bean> 

</beans> 

,但我得到的錯誤作爲

org.apache.catalina.LifecycleException: org.apache.catalina.LifecycleException: org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'context:annotation-config'. 

我使用glassfish作爲我的容器。

+0

您可以刪除''.As你已經添加了''做同樣的事情,即。啓用註釋加上它也掃描給定的包來找出bean。 – xyz 2012-07-17 10:56:28

+0

嗨Ajinkya,刪除註釋配置後的事件>我得到同樣的錯誤。 – vvekselva 2012-07-17 11:36:54

回答

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" 
xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-3.0.xsd"> 

<context:annotation-config /> 
<context:component-scan base-package="controllers"> 
</context:component-scan> 


<bean id="viewResolver" 
    class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
    <property name="viewClass" 
     value="org.springframework.web.servlet.view.JstlView" /> 
    <property name="prefix" value="/jsp/" /> 
    <property name="suffix" value=".jsp" /> 
</bean> 

</beans> 
+0

即使在更改定義後它不起作用。 – vvekselva 2012-07-18 17:10:04

+0

現在我得到org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException:來自ServletContext資源的XML文檔中的第9行[/WEB-INF/applicationContext.xml]無效;嵌套異常是org.xml.sax.SAXParseException:cvc-elt.1:找不到元素'beans:beans'的聲明。作爲錯誤 – vvekselva 2012-07-18 17:13:43

+0

你關閉了bean標籤?檢查更新的模式。是這樣嗎? – shazinltc 2012-07-19 01:57:30

2

你從哪裏得到那些模式版本。

變化

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

<beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:context="http://www.springframework.com/schema/context" 
xsi:schemaLocation="http://www.springframework.org/schema/beans 
         http://www.springframework.org/schema/beans/spring-beans-3.1.xsd 
         http://www.springframework.org/schema/context 
         http://www.springframework.org/schema/context/spring-context-3.1.xsd"> 
+0

我使用彈簧3.2罐甚至那麼我應該使用3.1 xsd? – vvekselva 2012-07-17 11:13:42

+1

是的,除非他們已經發布了3.2模式(看起來不像他們) – MikePatel 2012-07-17 12:13:40

+0

它不工作。 – vvekselva 2012-07-18 17:10:52

2

它,我不相信這是xmlns:context="http://www.springframework.com/schema/context"xmlns:context="http://www.springframework.org/schema/context"

ORG,而不是COM。

我希望這有助於! :)

相關問題