这两天因为环境搭建的问题特别苦难,参考了一下网上的各种答案,决定自己试一下Spring-MVC启动所需要的jar包;
因为Spring-MVC是在Spring框架下,索性从零开始我们引入需要的jar包;
maven下创建工程老师还没有讲解,这里采用eclipse的Dynamic Web Project来搭建环境;
首先配置web.xml
1 <?xml version="1.0" encoding="UTF-8"?> 2 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 3 xmlns="http://xmlns.jcp.org/xml/ns/javaee" 4 xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" 5 id="WebApp_ID" version="3.1"> 6 <servlet> 7 <servlet-name>springMVC</servlet-name> 8 <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 9 <init-param> 10 <param-name>contextConfigLocation</param-name> 11 <param-value>/WEB-INF/servlet-context.xml</param-value> 12 </init-param> 13 <load-on-startup>1</load-on-startup> 14 </servlet> 15 <servlet-mapping> 16 <servlet-name>springMVC</servlet-name> 17 <url-pattern>/</url-pattern> 18 </servlet-mapping> 19 20 <display-name>Test</display-name> 21 <welcome-file-list> 22 <welcome-file>index.html</welcome-file> 23 <welcome-file>index.htm</welcome-file> 24 <welcome-file>index.jsp</welcome-file> 25 <welcome-file>default.html</welcome-file> 26 <welcome-file>default.htm</welcome-file> 27 <welcome-file>default.jsp</welcome-file> 28 </welcome-file-list> 29 </web-app>
然后配置spring-MVC的xml→servlet-context.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.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.xsd"> <annotation-driven /> <context:component-scan base-package="spitter" /> <beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <beans:property name="prefix" value="/WEB-INF/views/" /> <beans:property name="suffix" value=".jsp" /> </beans:bean> <resources mapping="/resources/**" location="/resources/" /> <!-- <view-controller path="/" view-name="home" /> --> </beans:beans>
启动项目
tomcat8.5启动报错
java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet
把spring-web-4.2.3.RELEASE.jar 拖到/WEB-INF/lib/目录下,Refresh一下工程;
再次启动项目后报错
java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet
把spring-webmvc-4.2.3.RELEASE.jar 拖到/WEB-INF/lib/目录下,Refresh一下工程;
再次启动项目后报错
java.lang.ClassNotFoundException: org.springframework.context.ApplicationContextAware
把spring-context-4.2.3.RELEASE.jar 拖到/WEB-INF/lib/目录下,Refresh一下工程;
再次启动项目后报错
java.lang.ClassNotFoundException: org.springframework.beans.factory.Aware
把spring-beans-4.2.3.RELEASE.jar 拖到/WEB-INF/lib/目录下,Refresh一下工程;
再次启动项目后报错
java.lang.ClassNotFoundException: org.springframework.core.env.EnvironmentCapable
把spring-core-4.2.3.RELEASE.jar 拖到/WEB-INF/lib/目录下,Refresh一下工程;
再次启动项目后报错
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException:
时间: 2024-10-06 11:43:39