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

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

  

spring和springMVC的上下文的更多相关文章

  1. 走进spring之springmvc实战篇(一)

    本篇运用springmvc来试着写一个登录注册页面 在动手之前,我们需要了解下springnvc.这里先献上一张springmvc的流程图及讲解. Spring的MVC框架是一个基于Dispatche ...

  2. Spring以及SPringmvc相关问题: ServletContext -父子容器

    总结如下: 明确了Servlet规范中ServletContext的作用和意义.此外明确一个Tomcat中多个web应用,每个人web应用有唯一的一个ServletContext(全局上下文).[例子 ...

  3. logback与Spring、SpringMVC结合使用教程(转) logback good

    摘要:本文主要介绍了如何在spring.springMVC中使用logback 一.logback与Spirng结合使用 1.maven添加引用: <dependency> <gro ...

  4. 走进spring之springmvc

    走进spring之springmvc 在动手之前,我们需要了解下springnvc.这里先献上一张springmvc的流程图及讲解. Spring的MVC框架是一个基于DispatcherServle ...

  5. 【转】Spring学习---为什么要用spring,springMVC

    [原文]https://www.toutiao.com/i6593182323095634445/ 首先,软件里有很多优秀的框架,有一种类型的框架,它的特点是建立在一个现有技术的基础上,提供和现有技术 ...

  6. Spring 、SpringMVC 、Struts2之间的区别

    一.Spring与SpringMVC的区别: spring是一个开源框架,是为了解决企业应用程序开发,功能如下: 功能:使用基本的JavaBean代替EJB,并提供了更多的企业应用功能 范围:任何Ja ...

  7. 关于Spring和SpringMVC的一点感悟

    一年前,我们项目最开始使用的SSH(spring+springmvc+hibernate),那时候项目经理搭建好了框架就交给了我们,后来在一次配置事务的过程中,出现了大名鼎鼎的no seesion. ...

  8. 杂谈spring、springMVC

    一.背景 目前项目组都在用SSM(spring+springMVC+mybatis)开发项目 大家基本都停留在框架的基本使用阶段,对框架的职责并不清晰,导致配置文件出现了不少问题 在这简单讲解一下sp ...

  9. spring与springmvc父子容器

    转载地址:http://www.tianshouzhi.com/api/tutorials/spring 1.spring和springmvc父子容器概念介绍 在spring和springmvc进行整 ...

随机推荐

  1. 根据字符串获取对应类型(Type) 转

    public static Type GetTypeByString(string type)        {            switch (type.ToLower())          ...

  2. Eva's Problem

    Eva's Problem Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 20000/10000K (Java/Other) Total ...

  3. swap in java?

    Is it possible to write a swap method in java? these two variables will be primitives. It's not poss ...

  4. 关于用模拟器运行百度地图API无法定位的问题 - 不能用模拟器

    模拟器是没有办法定位,当你加入定位模块的时候,传出的参数都是空的. 定位的这个方法函数,是通过回调接口来实现,而且触发该事件的时候,需要经纬度位置改变.官方文档写得很清楚,简单点来说,就是你没有GPS ...

  5. SQL SERVER 2000 遍历父子关系数据的表(二叉树)获得所有子节点 所有父节点及节点层数函数

    ---SQL SERVER 2000 遍历父子关系數據表(二叉树)获得所有子节点 所有父节点及节点层数函数---Geovin Du 涂聚文--建立測試環境Create Table GeovinDu([ ...

  6. Android Studio 如何将包名按层级展示

    在project视图右上角有个“设置”的按钮,点开,然后将上图所圈部分去勾选就可以了.

  7. cssText笔记

    style.cssText 用来获取/设置元素的样式 设置: <div id= "a" style= "background: red;"> doc ...

  8. AJax的异步请求

    AJax的处理过程 1、传统的Web请求过程: 一般的 Web 应用程序中,用户填写表单字段并单击 Submit 按钮.然后整个表单发送到服务器,服务器将它转发给处理表单的脚本(通常是 PHP 或 J ...

  9. Python 3.5.1 Syntax & APIs(Continue Updating..

    print(x, end=' ') instead of print(x) to escape the default line-changing-output. print(str.ljust(si ...

  10. 观光公交noip<贪心>

    题目链接:https://www.oj.swust.edu.cn/problem/show/1190 思路: 每在一段路上使用一次加速器,就会对某些人或者说某些路段上的人产生影响,目的是使产生的影响最 ...