1. 如何用java类配置Spring MVC
1.方法一:在初始化时保存ApplicationContext对象
代码:
ApplicationContext ac = new ("applicationContext.xml");
ac.getBean("beanId");
说明:这种方式适用于采用Spring框架的独立应用程序,需要程序通过配置文件手工初始化Spring的情况。
2.方法二:通过Spring提供的工具类获取ApplicationContext对象
代码:
import org.springframework.web.context.support.WebApplicationContextUtils;
ApplicationContext ac1 = WebApplicationContextUtils.(ServletContext sc);
ApplicationContext ac2 = WebApplicationContextUtils.getWebApplicationContext(ServletContext sc);
ac1.getBean("beanId");
ac2.getBean("beanId");
说明:
这种方式适合于采用Spring框架的B/S系统,通过ServletContext对象获取ApplicationContext对象,然后在通过它获取需要的类实例。
上面两个工具方式的区别是,前者在获取失败时抛出异常,后者返回null。
其中 servletContext sc 可以具体 换成 servlet.getServletContext()或者 this.getServletContext() 或者 request.getSession().getServletContext(); 另外,由于spring是注入的对象放在ServletContext中的,所以可以直接在ServletContext取出 WebApplicationContext 对象: WebApplicationContext webApplicationContext = (WebApplicationContext) servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
3.方法三:继承自抽象类ApplicationObjectSupport
说明:抽象类ApplicationObjectSupport提供getApplicationContext()方法,可以方便的获取到ApplicationContext。
Spring初始化时,会通过该抽象类的setApplicationContext(ApplicationContext context)方法将ApplicationContext 对象注入。
4.方法四:继承自抽象类WebApplicationObjectSupport
说明:类似上面方法,调用getWebApplicationContext()获取WebApplicationContext
5.方法五:实现接口ApplicationContextAware
说明:实现该接口的setApplicationContext(ApplicationContext context)方法,并保存ApplicationContext 对象。
Spring初始化时,会通过该方法将ApplicationContext对象注入。
2. 当前java web 开发用得一般都是哪些框架
1.S2SH(struts2+spring+hibernate)
基于Struts2+Spring3+Hibernate4开发java Web企业应用开源框架s2jh源码分享
spring+hibernate+struts2开发OA企业办公管理系统源码分享
Struts2+Hibernate3+Spring三大框架技术实现MySQL数据分页
Spring+struts2+hibernate+easyui基础权限管理框架
Spring+Struts2+Hibernate三大框架开发企业人力资源管理系统源代码下载
Spring mvc+struts2+Hibernate整合实例代码(注解详解)
2.S2SM(struts2+spring+mybatis)
Spring+Struts2+mybatis手动配置三大框架整合源代码下载
Struts2+mybatis开发音乐分享系统
3.SSH(spring mvc+spring+hibernate或struts+spring+hibernate)
Spring MVC+Spring+Hibrenarte实现的简单的CRUD项目实例
springMVC注解与hibernate完美结合完成基本的增删改查demo源码下载
springmvc+hibernate+spring+easyui开发bsalse进销存后台管理系统源代码下载
spring 3.0+spring MVC+Hibernate框架搭建教程(附:springMVC文件上传功能)
spring+struts2+Hibernate三大框架开发某制药厂管理系统源代码下载
Spring mvc+struts2+Hibernate整合实例代码(注解详解)
4.SSM(spring mvc+spring+mybatis)
SpringMVC+Mybatis整合实现简单权限控制系统代码
3. 《看透SpringMVC源代码分析与实践》pdf下载在线阅读,求百度网盘云资源
《看透Spring MVC》(韩路彪)电子书网盘下载免费在线阅读
资源链接:
链接:
书名:看透Spring MVC
作者:韩路彪
豆瓣评分:6.8
出版社:机械工业出版社
出版年份:2016-1-1
页数:309
内容简介:
国内资深Web开发专家根据Spring MVC全新技术撰写,基于实际生产环境,从基础知识、源代码和实战3个维度对Spring MVC的结构和实现进行详细讲解
全面介绍Spring MVC的架构、原理、核心概念和操作,通过案例完整呈现Tomcat的实现,系统总结Spring MVC九大组件的处理以及常用的技巧和实践
在大型网站和复杂系统的开发中,Java具有天然的优势,而在Java的Web框架中Spring MVC以其强大的功能以及简单且灵活的用法受到越来越多开发者的青睐。本书不仅详细地分析Spring MVC的结构及其实现细节,而且讲解网站的不同架构及其演变的过程,以及网络底层协议的概念及其实现方法,帮助读者开发更高效的网站。
通过本书,你将:
系统学习网站的各种架构以及每种架构所针对的问题。
深入分析Web底层协议及其实现方法。
系统理解Spring MVC框架,为灵活开发高质量产品打下坚实基础。
深入理解Spring MVC的编程技巧和设计理念,提高综合思考、整体架构的能力。
学习作者自研的源代码分析方法——器用分析法,高效学习程序源代码。