博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
spring和springMVC的上下文
阅读量:6909 次
发布时间:2019-06-27

本文共 1167 字,大约阅读时间需要 3 分钟。

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

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;@Controllerpublic 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";	}}

  

转载于:https://www.cnblogs.com/wujixing/p/5606964.html

你可能感兴趣的文章
android和iOS平台的崩溃捕获和收集
查看>>
sql执行计划[Oracle] 变量绑定
查看>>
[Swift A] - Welcome to Swift
查看>>
Tomcat – java.lang.OutOfMemoryError: PermGen space Cause and Solution
查看>>
python3.4学习笔记(二十三) Python调用淘宝IP库获取IP归属地返回省市运营商实例代码...
查看>>
SQL Server的镜像是基于物理块变化的复制 镜像Failover之后数据的预热问题
查看>>
STL 清除模板容器 clear.h
查看>>
gradle多模块开发(转)
查看>>
Linux 网络编程一(TCP/IP协议)
查看>>
ckplayer 实现
查看>>
Redis Sentinel机制与用法(一)
查看>>
C#中常用接口介绍
查看>>
win10 提速
查看>>
kendoUpload
查看>>
zookeeper集群的部署
查看>>
在java项目中怎样利用Dom4j解析XML文件获取数据
查看>>
Android4.0-4.4 加入支持状态栏显示耳机图标方法(支持带不带MIC的两种耳机自己主动识别)...
查看>>
base标签的作用是什么
查看>>
Mac Apache WebDav 服务器配置
查看>>
Mac XMPP Openfire 服务器配置
查看>>