SpringMVC4.2.4 xml配置
环境:1、基于spring4.2.4版本,也是spring当前(2016.2)最新的GA版本
2、maven 3.2.1
3、jdk1.7
xml配置1:
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>SpringMVC</display-name> <!-- Spring配置;MyBatis配置 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring.xml</param-value> <!-- classpath:spring.xml,classpath:spring-mybatis.xml -->
</context-param> <listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> <!-- Spring MVC配置 -->
<servlet>
<servlet-name>dispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet> <servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping> </web-app>
xml配置2:spring与springMVC的配置文件没有放在默认的WEB-INF下面,而是放在src/main/resources下面
spring.xml 主要作用就是扫描非controller的bean,同时也可以承担引入外部属性文件,比喻mybatis的属性文件(连接字符串)
<?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"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
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
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd"> <context:annotation-config /> <!-- 扫描默认包下的所有的@Component注解,并且自动注册到容器中, 同时也扫描@Controller,@Service,@Respository这三个注解,他们是继承自@Component。
Spring根容器负责所有其他非controller的Bean的注册 -->
<context:component-scan base-package="com.wucj">
<context:exclude-filter type="annotation"
expression="org.springframework.stereotype.Controller" />
</context:component-scan> </beans>
springMVC.xml
<?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"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
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
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd"> <!-- 启用Spring基于annotation的DI, 使用户可以在Spring MVC中使用Spring的强大功能。 激活 @Required,@Autowired,JSR
250's @PostConstruct, @PreDestroy and @Resource 等标注 -->
<context:annotation-config /> <!-- SpringMVC只负责controller相关的Bean的注册 -->
<context:component-scan base-package="com.wucj.controller" /> <!-- 扩充了注解驱动,可以将请求参数绑定到控制器参数 -->
<mvc:annotation-driven /> <bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/" />
<property name="suffix" value=".jsp" />
</bean> </beans>
SpringMVC4.2.4 xml配置的更多相关文章
- SpringMVC、SpringMVC XML配置(纯XML方式)
1.引入SrpingMVC所使用的Java包: cglib-nodep-2.1_3.jar.commons-logging.jar.spring-aspects-4.1.7.RELEASE.jar.s ...
- ssm整合(基于xml配置方式)
本文是基于xml配置的方式来整合SpringMVC.Spring和Mybatis(基于注解的方式会再写一篇文章),步骤如下: (1)首先自然是依赖包的配置文件 pom.xml <project ...
- Maven-SSM项目pom.xml配置以及springmvc配置以及mybatis配置及web.xml配置
一.Maven本地仓库的pom.xml配置 (全部是mysql数据库) <project xmlns="http://maven.apache.org/POM/4.0.0" ...
- SpringMvc4.2.5 零配置出现 No mapping found for HTTP request with URI(转)
原文地址:SpringMvc4.2.5 零配置出现 No mapping found for HTTP request with URI 采用 spring 零配置,参考 http://hanqunf ...
- springmvc.xml和applicationContext.xml配置的特点
1:springmvc.xml配置要点 一般它主要配置Controller的组件扫描器和视图解析器 下为:springmvc.xml文件 <?xml version="1.0" ...
- SpringMVC学习(二)——基于xml配置的springMVC项目(maven+spring4)
可运行的附件地址:http://files.cnblogs.com/files/douJiangYouTiao888/springWithXML.zip 项目说明: 作者环境:maven3+jdk1. ...
- spring 5.x 系列第1篇 —— springmvc基础 (xml配置方式)
文章目录 一.搭建hello spring工程 1.1 项目搭建 1.2 相关配置讲解 二.配置自定义拦截器 三.全局异常处理 四.参数绑定 4.1 参数绑定 4.2 关于日期格式转换的三种方法 五. ...
- Mybatis XML配置
Mybatis常用带有禁用缓存的XML配置 <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE ...
- SpringMvc的xml配置与annotation配置的例子的区别
1.导入jar包时,要在xml配置基础上加 spring-aop-4.2.2.RELEASE.jar (注解的时候需要) 2.编写controller的时候要annotation需要做相关配置即红色部 ...
随机推荐
- Jquery获取第一个子元素
如获取id为divId的div下的第一个子div $("#divId").children("div").get(0) 但得到的是一个dom对象,如果要得到Jq ...
- String.IsNullOrEmpty 方法
参数 value:一个String引用 返回值 如果 value 参数为 空引用(在 Visual Basic 中为 Nothing) 或空字符串 (""),则为 true:否则为 ...
- Linux 中直接 I/O 机制的介绍
https://www.ibm.com/developerworks/cn/linux/l-cn-directio/ 对于传统的操作系统来说,普通的 I/O 操作一般会被内核缓存,这种 I/O 被称作 ...
- HDU 2227-Find the nondecreasing subsequences(dp+BIT优化)
题意: 给你一个序列a[],求它的不降子序列的个数 分析: dp[i]表示以i结尾不降子序列的个数,dp[i]=sum(dp[j])+1(j<i&&a[j]<=a[i]); ...
- Ubuntu 14.04配置FTP服务器
搭建: 1.sudo apt-get update #更新软件 2.sudo apt-get install vsftpd ...
- 利用Spring.Net技术打造可切换的分布式缓存读写类
利用Spring.Net技术打造可切换的Memcached分布式缓存读写类 Memcached是一个高性能的分布式内存对象缓存系统,因为工作在内存,读写速率比数据库高的不是一般的多,和Radis一样具 ...
- 【暑假】[实用数据结构]UVAlive 3135 Argus
UVAlive 3135 Argus Argus Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %l ...
- CSS_网站配色参考方案
http://www.cnblogs.com/QLeelulu/archive/2008/04/04/1136974.html Shiny silver [#EEEEEE] Reddi ...
- dedecms
http://www.duodede.com/free/ [free templte] http://www.xiuzhanwang.net/d
- 第二百四十天 how can I 坚持
在家待了一天,晚上出去买了个帽子,还有买了点排骨炖着吃了... 玩了好多局游戏. 想搞个直播,不知道能不能玩的起来. 水平太菜了,明天去小米之家玩玩. 睡觉.