在web.xml中配置,使用配置类替代springmvc.xml和applicationContext.xml
来源:互联网 发布:怎么用u盘导出考勤数据 编辑:程序博客网 时间:2024/06/05 14:36
1、在web.xml配置,让spring mvc在启动的时候,从带有@Configuration注解的类上加载配置,要在Spring MVC中使用基于java的配置,我们需要告诉DispatchServlet和ContextLoaderListener使用AnnotationConfigWebApplicationContext,这是WebApplicationContext的实现类,他会加载java配置类,而不是xml。要实现这种配置,我们可以设置contextClass上下文参数以及DispatcherServlet的初始化参数。如下所示
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http//java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- 让applicationContext.xml使用java配置 -->
<context-param>
<param-name>contextClass</param-name>
<param-value>
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
</param-value>
</context-param>
<!-- 指定根配置类,相当于applicationContext.xml中的配置 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>根配置类的全类名</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<!-- 让dispatcherServlet使用java配置 -->
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<!-- 告诉springmvc.xml使用java配置 -->
<init-param>
<param-name>contextClass</param-name>
<param-value>
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
</param-value>
</init-param>
<!-- 指定dispatcherServlet配置类 -->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
实现了WebMvcConfigurerAdapter的配置类,相当于springmvc.xml
</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
0 0
- 在web.xml中配置,使用配置类替代springmvc.xml和applicationContext.xml
- SpringMVC applicationContext.xml配置
- springjdbc中applicationContext.xml和web.xml配置信息
- spring的applicationContext.xml在web.xml中的配置详解
- applicationContext.xml 配置文件在web.xml中的配置详解
- spring web.xml applicationContext.xml常见配置
- SSH中 applicationcontext.xml与web.xml的配置
- SpringMVC web.xml配置
- SpringMVC web.xml配置
- 在web.xml中配置SpringMVC的启动配置项
- Spring中,applicationContext.xml 配置文件在web.xml中的配置详解
- Spring中,applicationContext.xml 配置文件在web.xml中的配置详解
- Spring中,applicationContext.xml 配置文件在web.xml中的配置详解
- spring中applicationContext.xml在web.xml中的配置路径说明
- Spring中,applicationContext.xml 配置文件在web.xml中的配置详解
- beans.xml 和 applicationContext.xml配置区别
- springMvc在web.xml文件的配置
- springmvc在web.xml配置路径后缀
- java.util.Date和mysql日期之间转换
- invalidate和postInvalidate 的区别及使用
- hadoop fs -put上传失败
- redis菜鸟教程
- “(null)” is of a model that is not supported by this version of Xcode. Please use a different device
- 在web.xml中配置,使用配置类替代springmvc.xml和applicationContext.xml
- acpi 表中对spcr的parse来初始化串口
- 杂记
- Shell脚本
- 基于单目RGB的SLAM
- 一个环境变量导致运行报错Exception in thread "main" java.lang.NoClassDefFoundError:
- 自然对数
- vim两套高级配置快捷命令
- 添加自定义View的Widget