diff --git a/org.springframework.web/src/main/java/org/springframework/web/context/support/SpringBeanAutowiringSupport.java b/org.springframework.web/src/main/java/org/springframework/web/context/support/SpringBeanAutowiringSupport.java index b8536ffdb27..93c00b96d42 100644 --- a/org.springframework.web/src/main/java/org/springframework/web/context/support/SpringBeanAutowiringSupport.java +++ b/org.springframework.web/src/main/java/org/springframework/web/context/support/SpringBeanAutowiringSupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2007 the original author or authors. + * Copyright 2002-2008 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,8 @@ package org.springframework.web.context.support; +import javax.servlet.ServletContext; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -91,4 +93,21 @@ public abstract class SpringBeanAutowiringSupport { } } + + /** + * Process @Autowired injection for the given target object, + * based on the current root web application context as stored in the ServletContext. + *

Intended for use as a delegate. + * @param target the target object to process + * @param servletContext the ServletContext to find the Spring web application context in + * @see WebApplicationContextUtils#getWebApplicationContext(javax.servlet.ServletContext) + */ + public static void processInjectionBasedOnServletContext(Object target, ServletContext servletContext) { + Assert.notNull(target, "Target object must not be null"); + WebApplicationContext cc = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext); + AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); + bpp.setBeanFactory(cc.getAutowireCapableBeanFactory()); + bpp.processInjection(target); + } + }