Servlet [springDispatcherServlet] in web application [/] threw load() exception

在搭建spring mvc,maven web项目时,遇到了这样一个问题:访问index.jsp是可以的,但就是访问不到controller层映射的jsp地址,网上搜了很多办法,从昨天开始,到现在,终于解决了,昨天搜的办法都无效,有说什么配置文件问题的,web.xml配置问题,application-servlet.xml配置问题,我就是很奇怪,我的配置文件是对的,不知道为什么会出错,今天意外间又搜到一个答案,竟然解决了 ,哈哈哈,有时候真的觉得,问题到了一定时间真的会自然解决,之前很多次也是这样,神奇了。


要把依赖都加到classpath下:

步骤:项目右键->properties->Deployment Assembly-->add-->Java Build Path Entries->Maven dependencies

再 项目右键->maven ->update ,重启项目就可以啦。

虽然解决了,但我其实还是有点怀疑的, 因为我昨天的时候,一开始是可以访问的,后面我不知道为啥特然就访问不到了,在此期间我也没改配置文件,只是加了个controller,表示很奇怪。

然后今天把依赖加到classpath下竟然好了

把我的项目目录粘一下:以便我以后参考哈哈哈哈


重要的就是web.xml和applicationContext-servlet.xml的配置了

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns="http://xmlns.jcp.org/xml/ns/javaee"
	xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
	id="WebApp_ID" version="3.1">

	<!-- 配置DispatcherServlet -->
	<!-- The front controller of this Spring Web application, responsible for handling all application requests -->
	<servlet>
		<servlet-name>springDispatcherServlet</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<!-- 配置DispatcherServlet的一个初始化参数:配置SpringMvc配置文件的位置和名称 -->
		<!-- 实际上也可以不通过 contextConfigLocation 来配置Spring MVC的配置文件,而使用默认的
			  默认的配置文件为: /WEB-INF/<servlet-name>-servlet.xml
		 -->
		
		<init-param>
			<param-name>contextConfigLocation</param-name>
			<param-value>classpath:applicationContext-servlet.xml</param-value>
		</init-param>
		
		<!-- 默认的 -->
		
		<load-on-startup>1</load-on-startup>
	</servlet>

	<!-- Map all requests to the DispatcherServlet for handling -->
	<servlet-mapping>
		<servlet-name>springDispatcherServlet</servlet-name>
		<url-pattern>/</url-pattern>
	</servlet-mapping>
	
</web-app>

这是我之前看视频学到的web.xml的配置。

applicationContex-servlet.xml:

<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:mvc="http://www.springframework.org/schema/mvc"
	xsi:schemaLocation="http://www.springframework.org/schema/beans   
           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  
           http://www.springframework.org/schema/mvc  
           http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
           http://www.springframework.org/schema/context   
           http://www.springframework.org/schema/context/spring-context-3.0.xsd">
	<!-- 自动扫描com.baobaotao.web 包下的@Controller标注的类控制器类 -->
	<context:component-scan base-package="com" />
	
	<!-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射 -->
	<mvc:annotation-driven />

	<!-- 对模型视图名称的解析,在请求时模型视图名称添加前后缀 -->
	<bean
		class="org.springframework.web.servlet.view.InternalResourceViewResolver"
		p:prefix="/WEB-INF/"
		p:suffix=".jsp" />
</beans>  

现在觉得配置文件其实蛮简单的嘛,没什么太多东西,搞不懂自己为什么卡壳那么久....


javax.servlet.ServletException: Could not resolve view with name 'employeeLog/emWorkLogDisplay' in servlet with name 'employeeLogManagement' org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1211) org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1011) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:955) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966) org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857) javax.servlet.http.HttpServlet.service(HttpServlet.java:618) org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842) javax.servlet.http.HttpServlet.service(HttpServlet.java:725) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118) org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:154) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:199) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:110) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:50) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192) org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160) org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:344) org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261) org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页