MVC3 一些杂七杂八的东西
来源:互联网 发布:网络直播广告植入 编辑:程序博客网 时间:2024/04/28 15:44
要解决的问题:
@RequestHeader annotation for MVC handler methods
@PathVariable annotation for MVC handler methods
@Value annotation for embedded expression support
introduced @CookieValue annotation for Servlet and Portlet MVC handler methods
introduced @ExceptionHandler annotation for used in annotated web controllers
@Transactional supports qualifier value for choosing between multiple transaction managers
猜想使用方法是两个注解一块使用,当有多个事务管理器时,通过qualifier注解来限定,只有bean的id为指定id的才可以。
@Transactional
@Qualifier("bean的名字")
added TxAnnotationDriven, MvcAnnotationDriven, etc. as out-of-the-box FeatureSpecifications
Spring 3.1的缓存相关的注解 @Cacheable、@CachePut、@CacheEvict <cache:advice>
综合的
@Configuration
@RequestPart
新产物RedirectAttributes
@RequestMapping(value = "/", method = RequestMethod.POST, consumes="application/json")
@RequestMapping(value = "/", method = RequestMethod.POST, produces="application/json")
如果随机随地取得spring容器管理的bena:
Spring容器在启动时,如果被Spring管理的Bean实现了ApplicationContextAware接口,那么会自动调用ApplicationContextAware接口中的
public void setApplicationContext(ApplicationContext context) throws BeansException
方法,向其传递ApplicationContext 对象。有了ApplicationContext 对象就可以取得所有的Spring管理的bean了。
我试过了,在双亲上下文环境上,可OK。这对于spring 3 MVC很重要。
配置文件:
<!-- 用于持有ApplicationContext,可以使用SpringContextHolder.getBean('xxxx')的静态方法得到spring bean对象 --><bean class="包名.SpringContextHolder" lazy-init="false" />
Demo:
//这段代码转自itEye上一位叫chenxin的朋友的Demoimport org.springframework.context.ApplicationContext;import org.springframework.context.ApplicationContextAware;/** * 以静态变量保存Spring ApplicationContext, 可在任何代码任何地方任何时候中取出ApplicaitonContext. * */public class SpringContextHolder implements ApplicationContextAware {private static ApplicationContext applicationContext;/** * 实现ApplicationContextAware接口的context注入函数, 将其存入静态变量. */public void setApplicationContext(ApplicationContext applicationContext) {SpringContextHolder.applicationContext = applicationContext; // NOSONAR}/** * 取得存储在静态变量中的ApplicationContext. */public static ApplicationContext getApplicationContext() {checkApplicationContext();return applicationContext;}/** * 从静态变量ApplicationContext中取得Bean, 自动转型为所赋值对象的类型. */@SuppressWarnings("unchecked")public static <T> T getBean(String name) {checkApplicationContext();return (T) applicationContext.getBean(name);}/** * 从静态变量ApplicationContext中取得Bean, 自动转型为所赋值对象的类型. */@SuppressWarnings("unchecked")public static <T> T getBean(Class<T> clazz) {checkApplicationContext();return (T) applicationContext.getBeansOfType(clazz);}/** * 清除applicationContext静态变量. */public static void cleanApplicationContext() {applicationContext = null;}private static void checkApplicationContext() {if (applicationContext == null) {throw new IllegalStateException("applicaitonContext未注入,请在applicationContext.xml中定义SpringContextHolder");}}}
- MVC3 一些杂七杂八的东西
- 一些杂七杂八的东西
- 一些杂七杂八的东西
- shell的一些杂七杂八的东西
- 杂七杂八的东西
- 杂七杂八的东西
- 杂七杂八的东西
- maven杂七杂八的东西
- 一些关于状压dp的杂七杂八的东西
- 杂七杂八的东西0 0
- Unity杂七杂八的些东西
- 一些杂七杂八的笔记
- 一些杂七杂八的问题
- 一些杂七杂八的总结
- ros移动机器人之SLAM (2)slam概述和一些杂七杂八的东西
- 关于 SYN_RECV 的杂七杂八的东西
- 关于路径的杂七杂八的东西理解
- 信号与系统杂七杂八的东西
- MVC 表单验证
- Macbook pro电池使用记录(一年了)
- 互联网协议入门(二)
- Project Web Access ActiveX控件 安装
- EHCache的使用
- MVC3 一些杂七杂八的东西
- IOS开发视频教程
- Java中《容器》的使用
- Mac OS 常用软件、杀毒、 鼠标滚轮方向控制软件
- XCode各版本对应的Mac OS操作系统版本
- MVC4
- Java Annotation详解(二): 反射和Annotation
- Mac OS 内存管理知识
- 一个才进入这个行业的菜鸟浅谈网络推广中最重要的三点