当前位置: 首页 > news >正文

MVC配置文件及位置

配置文件位置

默认位置

WEB-INF目录下,文件名:<servlet-name>-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaeehttp://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"version="4.0"><servlet><servlet-name>springmvc</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><load-on-startup>1</load-on-startup></servlet><servlet-mapping><servlet-name>springmvc</servlet-name><url-pattern>/</url-pattern></servlet-mapping>
</web-app>

指定位置

在web.xml中配置

        DispatcherServlet中的contextConfigLocation属性可以指定配置文件位置及文件名

确保配置文件存在于类路径(Resources)下

web.xml 

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaeehttp://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"version="4.0"><!--配置前端控制器--><servlet><servlet-name>springDispatcherServlet</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><!-- 手动设置 Spring MVC 配置文件的路径 --><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:springmvc.xml</param-value></init-param><!-- 服务器启动时初始化 Spring MVC 控制器 --><load-on-startup>1</load-on-startup></servlet><servlet-mapping><servlet-name>springDispatcherServlet</servlet-name><url-pattern>/</url-pattern></servlet-mapping>
</web-app>

SpringMVC容器文件

<?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.2.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd"><!-- 配置组件扫描 --><context:component-scan base-package="com.mvc" /><!--配置视图解析器[默认视图解析器]--><bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"><!--配置属性suffix 和 prefix--><property name="prefix" value="/WEB-INF/pages/"/><property name="suffix" value=".jsp"/><!--调整优先级--><property name="order" value="10"/></bean>
</beans>

http://www.lryc.cn/news/502828.html

相关文章:

  • 如何解决samba服务器共享文件夹不能粘贴文件
  • 【中工开发者】鸿蒙商城app
  • (九)机器学习 - 多项式回归
  • Qt编写区位码gb2312、机内码、国标码————附带详细介绍和编码实现
  • linux网络编程 | c | epoll实现IO多路转接服务器
  • Source Insight的使用经验汇总
  • VSCode 报错:rust-analyzer requires glibc >= 2.28 in latest build
  • Android Link to Death 使用
  • 【C++游记】string的使用和模拟实现
  • DockerUI info存在未授权访问漏洞
  • SQL,查询每天最接近指定时间的记录
  • ElasticSearch如何做性能优化?
  • 【Linux】虚拟空间布局模型地址回填数据段合并(万字详解)
  • const和修饰指针的几种用法
  • mybatis事务的自动提交与手动提交
  • 网络安全协议之比较(SSH、PKI、SET、SSL)
  • Vue的生命周期方法
  • ISP和IQ调试(一)
  • c# TaskScheduler
  • 可视化数据
  • 【Redis】Redis缓存击穿
  • 厦门凯酷全科技有限公司深耕抖音电商运营
  • 六西格玛DMAIC在企业得项目管理中有什么作用
  • vscode借助插件调试OpenFoam的正确的.vscode配置文件
  • SpringBoot整合JWT(JSON Web Token)生成token与验证
  • 把帕拉丁需要的.rom文件转成.bin
  • Nginx 缓存那些事儿:原理、配置和最佳实践
  • vue发展史
  • 基于Java和Vue开发的校园跑腿软件校园跑腿小程序系统源码
  • MySQL(五)--- 事务