`

servlet中得到spring的ApplicationContext

 
阅读更多
private static ApplicationContext ctx = null;
	
	private static Lock lock = new ReentrantLock();

	private ApplicationContext getApplicationContext() {
		if (ctx != null) {
			return ctx;
		}

        lock.lock();
        if (ctx != null) {
            lock.unlock();
            return ctx;
        }

		ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(this.getServletContext());
        lock.unlock();
		return ctx;
	}

分享到:
评论

相关推荐

    spring applicationContext 配置文件

    <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" p:order="0"> <property name="interceptors"> <list> <ref bean="doubleSubmitInterceptor"/> </list> ...

    spring4.3.9相关jar包

    可以找到使用Spring ApplicationContext特性时所需的全部类,JDNI 所需的全部类,instrumentation组件以及校验Validation 方面的相关类。 外部依赖spring-beans, (spring-aop)。 spring-jdbc.jar(必须) :这个jar...

    spring4.1核心包

    可以找到使用Spring ApplicationContext特性时所需的全部类,JDNI 所需的全部类,instrumentation组件以及校验Validation 方面的相关类。 外部依赖spring-beans, (spring-aop)。 5. spring-context-support-4.1.1....

    springweb3.0MVC注解(附实例)

    web.xml 中定义了一个名为 annomvc 的 Spring MVC 模块,按照 Spring MVC 的契约,需要在 WEB-INF/annomvc-servlet.xml 配置文件中定义 Spring MVC 模块的具体配置。annomvc-servlet.xml 的配置内容如下所示: ...

    CXF WebService整合Spring示例工程代码demo

    2.web工程的web.xml中配置CXFServlet <!-- 设置Spring容器加载配置文件路径 --> <param-name>contextConfigLocation <param-value>classpath*:applicationContext-server.xml <listener-class>org....

    Spring MVC 入门实例

    36 <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 37 <load-on-startup>1 38 </servlet> 39 40 <servlet-mapping> 41 <servlet-name>ideawu</servlet-name> 42 *.do 43 </...

    Spring中文帮助文档

    3.10. 以J2EE RAR文件的形式部署Spring ApplicationContext 3.11. 基于注解(Annotation-based)的配置 3.11.1. @Autowired 3.11.2. 基于注解的自动连接微调 3.11.3. CustomAutowireConfigurer 3.11.4. @...

    spring源代码解析

    从加载过程我们可以看到,首先从Servlet事件中得到ServletContext,然后可以读到配置好的在web.xml的中的各个属性值,然后ContextLoder实例化WebApplicationContext并完成其载入和初始化作为根上下文。当这个根上...

    Spring MVC 框架应用实例

    org.springframework.web.servlet.DispatcherServlet </servlet-class> <load-on-startup>1 </servlet> <servlet-mapping> <servlet-name>ideawu</servlet-name> *.do </servlet-mapping> ...

    ssh(structs,spring,hibernate)框架中的上传下载

    WEB-INF下的applicationContext.xml为Spring的配置文件,struts-config.xml为Struts的配置文件,file-upload.jsp为文件上传页面,file-list.jsp为文件列表页面。  本文后面的章节将从数据持久层->业务层->Web层的...

    spring-boot-reference.pdf

    Spring Boot Documentation 1. About the Documentation 2. Getting Help 3. First Steps 4. Working with Spring Boot 5. Learning about Spring Boot Features 6. Moving to Production 7. Advanced Topics II. ...

    spring-mvc代码示例+注释+文件解析(可直接运行)

    2、spring-mvc配置文件包括两部分,一个是spring传统配置文件,在代码中为“applicationContext.xml”,主要配置代码中各种bean以及依赖关系;另外一个是spring-mvc特有的配置文件,处理跳转的代理类得(相当于...

    Spring MVC Demo

    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <!--servlet的参数配置,查找controller位置的xml文件配置,此参数指定了spring配置文件的位置 ,如果你不指定的话,默认...

    spring_MVC源码

    -- 这里在配成spring,下边也要写一个名为spring-servlet.xml的文件,主要用来配置它的controller --> 19. *.do</url-pattern> 20. </servlet-mapping> 21. <welcome-file-list> 22. <welcome-file>index.jsp...

    Spring API

    3.10. 以J2EE RAR文件的形式部署Spring ApplicationContext 3.11. 基于注解(Annotation-based)的配置 3.11.1. @Autowired 3.11.2. 基于注解的自动连接微调 3.11.3. CustomAutowireConfigurer 3.11.4. @...

    Struts2+Spring3+MyBatis3完整实例

    网上的东西好大多都不能直接用,自己结合网上资料做了一个Struts2+Spring3+MyBatis3的测试工程,JUnit测试用例和WEB服务。 内涵完整jar包,解压直接可用,包括一个表文件。 Eclipse3.2+Tomcat/5.5+jdk1.5.0_17 - ...

    Spring.3.x企业应用开发实战(完整版).part2

    16.7.2 使用Spring Servlet API模拟对象 16.7.3 使用Spring RestTemplate测试 16.7.4 使用Selenium测试 16.8 小结 第17章 实战案例开发 17.1 论坛案例概述 17.1.1 论坛整体功能结构 17.1.2 论坛用例描述 17.1.3 主要...

    springmybatis

    1. 从配置文件(通常是XML配置文件中)得到 sessionfactory. 2. 由sessionfactory 产生 session 3. 在session 中完成对数据的增删改查和事务提交等. 4. 在用完之后关闭session 。 5. 在java 对象和 数据库之间有做...

    Spring.html

    Spring IOC 控制反转:把创建对象的权利交给Spring 创建对象 1.... 2.... 3.... ClassPathXmlApplicationContext:使用这个...在Servlet中使用WebApplicationContextUtils获取容器对象 5.使用容器对象去获取Service对象

    SpringMVC中的RootApplicationContext上下文和WebApplicationContext上下文,通过注解配置SpringMVC的完整解决方案

    注解配置SpringMVC原理简述1. 准备知识1.1 两个应用上下文1.2 ServletContext配置方法(Configuration Methods)1.3 运行时插拔1.4 SpringServletContainerInitializer1.4.1 AbstractContextLoaderInitializer1.4.2 ...

Global site tag (gtag.js) - Google Analytics