上下文可以替代注解, 但是注解更方便

package com.tgb.web.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import org.springframework.web.servlet.support.RequestContextUtils; @Controller
public class SpringController {
// @Resource(name="springService")
// private ISpring springService; @RequestMapping("/spring/get")
public String get(HttpServletRequest request){
//spring的上下文
WebApplicationContext ac1 = WebApplicationContextUtils.getWebApplicationContext(request.getSession().getServletContext());
//springMVC的上下文
WebApplicationContext ac2 = RequestContextUtils.getWebApplicationContext(request); //通过spring上下文拿到bean
//ISpring springService = (ISpring)ac1.getBean("springService"); //通过springMVC上下文拿到bean
ISpring springService = (ISpring)ac2.getBean("springService");
System.out.println(springService.get());
return "/success";
}
}

  

最新文章

  1. Linux下用ftp更新web内容!
  2. php导入excel
  3. 清空IE缓存
  4. [iOS翻译]《iOS 7 Programming Cookbook》:iOS文件与文件夹管理(上)
  5. [kuangbin带你飞]专题十五 数位DP
  6. open_table与opened_table --2
  7. linux根目录详解
  8. [置顶] RGB颜色查询对照表
  9. 中级Perl第二章习题
  10. HTML5简单入门系列(一)
  11. 【可视化】Echarts3 在世界地图中绘制中国各省份的轮廓
  12. 基于jq的表单填充
  13. ionic 3 常见报错及解决办法
  14. 【翻译】Flume 1.8.0 User Guide(用户指南)
  15. Django报错:提交表单报错---RuntimeError: You called this URL via POST, but the URL doesn’t end in a slash and you have APPEND_SLASH set.
  16. 学习JAVA第一章的心得
  17. 搭建SpringBoot、Jsp支持学习笔记
  18. Jmeter中的XPath Assertion
  19. Codeforces Round #256 (Div. 2) E Divisors
  20. php使用mysql之sql注入(功)

热门文章

  1. 转载-SharePoint 2010 WebPart与Google地图系列 一:创建显示地图的WebPart
  2. [转]Zend Studio 文件头和方法注释设置
  3. 给php代码添加规范的注释phpDocumentor
  4. Qt Creator下载和安装(详细教程)
  5. windows指令
  6. Python 模块功能paramiko SSH 远程执行及远程下载
  7. 禁止root远程登录 sshd问题:A protocol error occurred. Change of username or service not allowed
  8. Android OpenGL ES(四)关于EGL .
  9. POJ1308 Is It A Tree?
  10. NSIndexPath 延伸