springmvc框架搭建遇到的问题

慢慢成长的我 2016-07-08 05:44:55
我在搭建springmvc基本框架的时候,没有采用在WEB-INF文件夹下面创建springmvc-servlet.xml文件而是自定义的文件和创建文件的路径,web.xml文件代码如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>activitiProject</display-name>

<!-- Spring配置 -->
<!-- ====================================== -->

<!-- 指定Spring Bean的配置文件所在目录。默认配置在WEB-INF目录下 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:/META-INF/spring-core.xml</param-value>
</context-param>
<!--配置监听器listener, 如果不写这个就无法扫描到spring-core文件,相当于程序的入入口 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- ====================================== -->

<!-- Spring MVC配置 -->
<!-- ====================================== -->
<!--1、配置DispatcherServlet -->
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- 设置dispatchservlet的匹配模式 -->
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>*.action</url-pattern>
</servlet-mapping>
<!-- ====================================== -->

<!-- 字符集过滤器 -->
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>


但是部署程序的时候还是报错说找不到WEB-INF文件夹下面的springmvc-servlet.xml文件,不知道到底哪里配置有问题,请
知道的人解答一下,万分感谢啦
...全文
192 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
Intboy 2016-07-11
  • 打赏
  • 举报
回复
引用 5 楼 u012027337 的回复:
[quote=引用 1 楼 fengspg 的回复:] 自定义了就要指定你自定义的文件名和路径。
可是我的这段代码就是制定了自定义的文件路径和文件名啊
<!-- 指定Spring Bean的配置文件所在目录。默认配置在WEB-INF目录下 -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:/META-INF/spring-core.xml</param-value>
    </context-param>
    <!--配置监听器listener, 如果不写这个就无法扫描到spring-core文件,相当于程序的入入口 -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
[/quote] 这个是加载contextConfigLocation的,要配加载servlet的 如下:
	<servlet>
		<servlet-name>spring-mvc</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<init-param>
			<param-name>contextConfigLocation</param-name>
			<param-value>/WEB-INF/classes/spring-mvc.xml</param-value>
		</init-param>
		<load-on-startup>1</load-on-startup>
	</servlet>
慢慢成长的我 2016-07-11
  • 打赏
  • 举报
回复
郁闷死了,这个配置我测试是可以访问的网页的,报这个异常信息主要原因是: 在配置spring核心servlet时,如果没有对初始化的参数进行配置,会默认读取/WEB-INF/spring-servlet.xml,这时候就会出现上面的异常,解决方法是在配置spring核心servlet中加入初始化参数的配置,这个异常就不会出现了
u011086231 2016-07-11
  • 打赏
  • 举报
回复
你少了这个路径的配置吧。。
慢慢成长的我 2016-07-11
  • 打赏
  • 举报
回复
引用 4 楼 minxiaofeng10 的回复:
Classpath后加个*
之前是加*号的,但是还是不对,我就把*去掉额
慢慢成长的我 2016-07-11
  • 打赏
  • 举报
回复
引用 1 楼 fengspg 的回复:
自定义了就要指定你自定义的文件名和路径。
可是我的这段代码就是制定了自定义的文件路径和文件名啊
<!-- 指定Spring Bean的配置文件所在目录。默认配置在WEB-INF目录下 -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:/META-INF/spring-core.xml</param-value>
    </context-param>
    <!--配置监听器listener, 如果不写这个就无法扫描到spring-core文件,相当于程序的入入口 -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
minxiaofeng10 2016-07-08
  • 打赏
  • 举报
回复
Classpath后加个*
leizihaisir 2016-07-08
  • 打赏
  • 举报
回复
<servlet> <servlet-name>springMvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:springMvc-servlet.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springMvc</servlet-name> <url-pattern>*.html</url-pattern> </servlet-mapping>
leizihaisir 2016-07-08
  • 打赏
  • 举报
回复
<servlet> <servlet-name>springMvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:springMvc-servlet.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springMvc</servlet-name> <url-pattern>*.html</url-pattern> </servlet-mapping>
Intboy 2016-07-08
  • 打赏
  • 举报
回复
自定义了就要指定你自定义的文件名和路径。

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧