spring和springMVC的上下文
2024-08-26 21:57:47
上下文可以替代注解, 但是注解更方便
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";
}
}
最新文章
- Linux下用ftp更新web内容!
- php导入excel
- 清空IE缓存
- [iOS翻译]《iOS 7 Programming Cookbook》:iOS文件与文件夹管理(上)
- [kuangbin带你飞]专题十五 数位DP
- open_table与opened_table --2
- linux根目录详解
- [置顶] RGB颜色查询对照表
- 中级Perl第二章习题
- HTML5简单入门系列(一)
- 【可视化】Echarts3 在世界地图中绘制中国各省份的轮廓
- 基于jq的表单填充
- ionic 3 常见报错及解决办法
- 【翻译】Flume 1.8.0 User Guide(用户指南)
- Django报错:提交表单报错---RuntimeError: You called this URL via POST, but the URL doesn’t end in a slash and you have APPEND_SLASH set.
- 学习JAVA第一章的心得
- 搭建SpringBoot、Jsp支持学习笔记
- Jmeter中的XPath Assertion
- Codeforces Round #256 (Div. 2) E Divisors
- php使用mysql之sql注入(功)
热门文章
- 转载-SharePoint 2010 WebPart与Google地图系列 一:创建显示地图的WebPart
- [转]Zend Studio 文件头和方法注释设置
- 给php代码添加规范的注释phpDocumentor
- Qt Creator下载和安装(详细教程)
- windows指令
- Python 模块功能paramiko SSH 远程执行及远程下载
- 禁止root远程登录 sshd问题:A protocol error occurred. Change of username or service not allowed
- Android OpenGL ES(四)关于EGL .
- POJ1308 Is It A Tree?
- NSIndexPath 延伸