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需要做相关配置即红色部 ...
随机推荐
- $( ).focus()与$( )[0].focus()区别
$( #id).focus()与$( #id)[0].focus()没有区别,因为id必须是唯一的.如果同一页面出现多个相同的ID(这是不符合w3c规范的),$(#id)也只会拿到第一个该ID,后面的 ...
- Android常用组件
UI相关 图片 Android-Universal-Image-Loader:com.nostra13.universalimageloader:异步加载.缓存.显示图片 ImageLoader:co ...
- 1047图的深度优先遍历c语言
描述 图(graph)是数据结构 G=(V,E),其中V是G中结点的有限非空集合,结点的偶对称为边(edge):E是G中边的有限集合.设V={0,1,2,……,n-1},图中的结点又称为顶点(vert ...
- bjfu1097 图标排列
这是2011年百度之星的一道题.这题的做法就是找规律,规律找对了,代码极水.规律我一开始也没有找到,后来经人提醒,发现如下规律:对于每个开发者,其所有应用的分离度和一定是其第一个应用与最后一个应用的距 ...
- bjfu1235 两圆公共面积
给定两个圆,求其覆盖的面积,其实也就是求其公共面积(然后用两圆面积和减去此值即得最后结果). 我一开始是用计算几何的方法做的,结果始终不过.代码如下: /* * Author : ben */ #in ...
- ili9341 横屏驱动代码
void ili9341_Initializtion(void) { u16 i; RCC->APB2ENR|=<<; //使能PORTB时钟 GPIOB->CRH&= ...
- Unicode转为UTF8
Unicode转换为UTF8 要说这个转换也简单,使用WideCharToMultiByte两次或者直接一次就可以转换. 今天在弄VLC的时候,由于VLC的视频文件名使用UTF8编码,因此当路径中包含 ...
- bzoj 2818 Gcd(欧拉函数 | 莫比乌斯反演)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2818 [题意] 问(x,y)为质数的有序点对的数目. [思路一] 定义f[i]表示i之 ...
- 读《HTML5与CSS3权威指南(上册)》笔记
第二章 1.内容类型:“text/html”.DOCTYPE声明:<!DOCTYPE html>.指定字符编码:<meta charset="utf-8"> ...
- eucalyptus,openNebula云构建漫谈
Eucalyptus篇 万事在于理解,技术研究贵在入脑入心.生活很苦,乐趣何在,在于君心?不能修心,则诸事繁杂!闲来无事,阅读官网文档遇此 two Why selecter?因此分享给亲们!亲,那么我 ...