added "processInjectionBasedOnServletContext" variant
This commit is contained in:
parent
e863f9a371
commit
b05d800205
|
|
@ -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 <code>@Autowired</code> injection for the given target object,
|
||||
* based on the current root web application context as stored in the ServletContext.
|
||||
* <p>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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue