我从头开始创建HelloWorld web/spring应用程序。我跟着this tutorial为了学习如何使用mvc模式。因此,后完成了所有步骤,并开始运行我的控制台收到此错误的应用程序:严重:上下文初始化失败
墓:上下文初始化失败 org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: 行11 XML文档中的ServletContext资源 [/WEB-INF/dispatcher-servlet.xml]无效;嵌套的异常是 org.xml.sax.SAXParseException; lineNumber:11; columnNumber:100; cvc-complex-type.2.4.c
在SO问题中搜索我发现了像下面这样的威胁,但还没有解决我的错误。
- Cannot find the declaration of element 'beans' in internet offline mode
- Spring Security beginner's question. Build failed
因此,我推断,可能是在WEB-INF文件夹中的调度员servlet.xml中。这个XML的样子:
<?xml version="1.0" encoding="UTF-8"?>
<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"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
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">
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/jsp/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="interceptors">
<list>
<ref local="localeChangeInterceptor" />
</list>
</property>
<property name="urlMap">
<map>
<entry key="/hello.html">
<ref bean="helloController" />
</entry>
</map>
</property>
</bean>
<bean id="helloController" class="controllers.HelloController">
</bean>
<bean id="localeChangeInterceptor"
class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="hl" />
</bean>
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
</bean>
</beans>
最后,这些是我的罐子包括:
commons-logging-1.1.1.jar
org.springframework.aop-3.1.2.RELEASE.jar
org.springframework.asm-3.1.2.RELEASE.jar
org.springframework.aspects-3.1.2.RELEASE.jar
org.springframework.beans-3.1.2.RELEASE.jar
org.springframework.context-3.1.2.RELEASE.jar
org.springframework.context.support-3.1.2.RELEASE.jar
org.springframework.core-3.1.2.RELEASE.jar
org.springframework.expression-3.1.2.RELEASE.jar
org.springframework.instrument-3.1.2.RELEASE.jar
org.springframework.instrument.tomcat-3.1.2.RELEASE.jar
org.springframework.jdbc-3.1.2.RELEASE.jar
org.springframework.jms-3.1.2.RELEASE.jar
org.springframework.orm-3.1.2.RELEASE.jar
org.springframework.oxm-3.1.2.RELEASE.jar
org.springframework.spring-library-3.1.2.RELEASE.libd
org.springframework.test-3.1.2.RELEASE.jar
org.springframework.transaction-3.1.2.RELEASE.jar
org.springframework.web-3.1.2.RELEASE.jar
org.springframework.web.portlet-3.1.2.RELEASE.jar
org.springframework.web.servlet-3.1.2.RELEASE.jar
org.springframework.web.struts-3.1.2.RELEASE.jar
spring-webmvc-3.0.5.RELEASE.jar
在此先感谢
编辑1:
使@Biju Kunjummen的更改后,看起来像现在的问题是,在bean声明中有一个comflic:
Grave: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'urlMapping' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Cannot resolve reference to bean 'helloController' while setting bean property 'urlMap' with key [TypedStringValue: value [/hello.html], target type [null]]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'helloController' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [controllers.HelloController]: Constructor threw exception; nested exception is java.lang.Error: Unresolved compilation problems:
The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files
Implicit super constructor Object() is undefined for default constructor. Must define an explicit constructor
String cannot be resolved to a type
我检查了控制器和看起来很好为src/controllers
DIR:
package controllers;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
public class HelloController implements Controller {
public ModelAndView handleRequest(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
String Mess = "Hello World!";
ModelAndView modelAndView = new ModelAndView("hello");
modelAndView.addObject("message", Mess);
return modelAndView;
}
}
? – soulcheck 2012-08-08 16:15:50
当我从[Spring community](http://www.springsource.org/download/community)下载Spring框架时,它并没有进入,所以我用另一个链接下载它:[spring-webmvc-3.0.5 .RELEASE](http://search.maven.org/remotecontent?filepath=org/springframework/spring-webmvc/3.0.5.RELEASE/spring-webmvc-3.0.5.RELEASE.jar) – manix 2012-08-08 16:19:38
这里你去:http ://search.maven.org/remotecontent文件路径=组织/ springframework的/弹簧webmvc/3.1.2.RELEASE /弹簧webmvc-3.1.2.RELEASE.jar。 – soulcheck 2012-08-08 16:21:49