本文整理了Java中org.springframework.web.context.WebApplicationContext.getAutowireCapableBeanFactory()
方法的一些代码示例,展示了WebApplicationContext.getAutowireCapableBeanFactory()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebApplicationContext.getAutowireCapableBeanFactory()
方法的具体详情如下:
包路径:org.springframework.web.context.WebApplicationContext
类名称:WebApplicationContext
方法名:getAutowireCapableBeanFactory
暂无
代码示例来源:origin: stackoverflow.com
WebApplicationContext context = WebApplicationContextUtils
.getWebApplicationContext(getServletContext());
ctx = context.getAutowireCapableBeanFactory();
ctx.autowireBean(this);
代码示例来源:origin: spring-projects/spring-framework
@Override
public <T extends ConstraintValidator<?, ?>> T getInstance(Class<T> key) {
return getWebApplicationContext().getAutowireCapableBeanFactory().createBean(key);
}
代码示例来源:origin: spring-projects/spring-framework
public void releaseInstance(ConstraintValidator<?, ?> instance) {
getWebApplicationContext().getAutowireCapableBeanFactory().destroyBean(instance);
}
代码示例来源:origin: spring-projects/spring-framework
@Override
protected ViewPreparer getPreparer(String name, WebApplicationContext context) throws TilesException {
// Quick check on the concurrent map first, with minimal locking.
ViewPreparer preparer = this.sharedPreparers.get(name);
if (preparer == null) {
synchronized (this.sharedPreparers) {
preparer = this.sharedPreparers.get(name);
if (preparer == null) {
try {
Class<?> beanClass = ClassUtils.forName(name, context.getClassLoader());
if (!ViewPreparer.class.isAssignableFrom(beanClass)) {
throw new PreparerException(
"Invalid preparer class [" + name + "]: does not implement ViewPreparer interface");
}
preparer = (ViewPreparer) context.getAutowireCapableBeanFactory().createBean(beanClass);
this.sharedPreparers.put(name, preparer);
}
catch (ClassNotFoundException ex) {
throw new NoSuchPreparerException("Preparer class [" + name + "] not found", ex);
}
}
}
}
return preparer;
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Process {@code @Autowired} 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);
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Process {@code @Autowired} injection for the given target object,
* based on the current web application context.
* <p>Intended for use as a delegate.
* @param target the target object to process
* @see org.springframework.web.context.ContextLoader#getCurrentWebApplicationContext()
*/
public static void processInjectionBasedOnCurrentContext(Object target) {
Assert.notNull(target, "Target object must not be null");
WebApplicationContext cc = ContextLoader.getCurrentWebApplicationContext();
if (cc != null) {
AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
bpp.setBeanFactory(cc.getAutowireCapableBeanFactory());
bpp.processInjection(target);
}
else {
if (logger.isDebugEnabled()) {
logger.debug("Current WebApplicationContext is not available for processing of " +
ClassUtils.getShortName(target.getClass()) + ": " +
"Make sure this class gets constructed in a Spring web application. Proceeding without injection.");
}
}
}
代码示例来源:origin: org.springframework/spring-web
@Override
public <T extends ConstraintValidator<?, ?>> T getInstance(Class<T> key) {
return getWebApplicationContext().getAutowireCapableBeanFactory().createBean(key);
}
代码示例来源:origin: spring-projects/spring-framework
logger.trace("Creating new @ServerEndpoint instance of type " + endpointClass);
return wac.getAutowireCapableBeanFactory().createBean(endpointClass);
代码示例来源:origin: org.springframework/spring-web
public void releaseInstance(ConstraintValidator<?, ?> instance) {
getWebApplicationContext().getAutowireCapableBeanFactory().destroyBean(instance);
}
代码示例来源:origin: org.springframework/spring-webmvc
@Override
protected ViewPreparer getPreparer(String name, WebApplicationContext context) throws TilesException {
// Quick check on the concurrent map first, with minimal locking.
ViewPreparer preparer = this.sharedPreparers.get(name);
if (preparer == null) {
synchronized (this.sharedPreparers) {
preparer = this.sharedPreparers.get(name);
if (preparer == null) {
try {
Class<?> beanClass = ClassUtils.forName(name, context.getClassLoader());
if (!ViewPreparer.class.isAssignableFrom(beanClass)) {
throw new PreparerException(
"Invalid preparer class [" + name + "]: does not implement ViewPreparer interface");
}
preparer = (ViewPreparer) context.getAutowireCapableBeanFactory().createBean(beanClass);
this.sharedPreparers.put(name, preparer);
}
catch (ClassNotFoundException ex) {
throw new NoSuchPreparerException("Preparer class [" + name + "] not found", ex);
}
}
}
}
return preparer;
}
代码示例来源:origin: org.springframework/spring-web
/**
* Process {@code @Autowired} 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);
}
代码示例来源:origin: org.springframework/spring-web
/**
* Process {@code @Autowired} injection for the given target object,
* based on the current web application context.
* <p>Intended for use as a delegate.
* @param target the target object to process
* @see org.springframework.web.context.ContextLoader#getCurrentWebApplicationContext()
*/
public static void processInjectionBasedOnCurrentContext(Object target) {
Assert.notNull(target, "Target object must not be null");
WebApplicationContext cc = ContextLoader.getCurrentWebApplicationContext();
if (cc != null) {
AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
bpp.setBeanFactory(cc.getAutowireCapableBeanFactory());
bpp.processInjection(target);
}
else {
if (logger.isDebugEnabled()) {
logger.debug("Current WebApplicationContext is not available for processing of " +
ClassUtils.getShortName(target.getClass()) + ": " +
"Make sure this class gets constructed in a Spring web application. Proceeding without injection.");
}
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test // SPR-13375
@SuppressWarnings("rawtypes")
public void springHandlerInstantiator() {
TestStandaloneMockMvcBuilder builder = new TestStandaloneMockMvcBuilder(new PersonController());
builder.build();
SpringHandlerInstantiator instantiator = new SpringHandlerInstantiator(builder.wac.getAutowireCapableBeanFactory());
JsonSerializer serializer = instantiator.serializerInstance(null, null, UnknownSerializer.class);
assertNotNull(serializer);
}
代码示例来源:origin: paoding-code/paoding-rose
/**
* 注册一个 {@link ViewDispatcher}定义到上下文中,以被这个类的所有实例使用
*
*/
protected ViewDispatcher registerViewDispatcher(WebApplicationContext applicationContext) {
// 并发下,重复注册虽然不会错误,但没有必要重复注册
synchronized (applicationContext) {
if (SpringUtils.getBean(applicationContext, viewDispatcherName) == null) {
GenericBeanDefinition beanDefinition = new AnnotatedGenericBeanDefinition(
ViewDispatcherImpl.class);
((BeanDefinitionRegistry) applicationContext.getAutowireCapableBeanFactory())
.registerBeanDefinition(viewDispatcherName, beanDefinition);
if (logger.isDebugEnabled()) {
logger
.debug("registered bean definition:"
+ ViewDispatcherImpl.class.getName());
}
}
return (ViewDispatcher) SpringUtils.getBean(applicationContext, viewDispatcherName);
}
}
}
代码示例来源:origin: ryantenney/metrics-spring
@Override
public void contextInitialized(ServletContextEvent event) {
WebApplicationContextUtils.getRequiredWebApplicationContext(event.getServletContext()).getAutowireCapableBeanFactory().autowireBean(this);
metricsServletContextListener.contextInitialized(event);
healthCheckServletContextListener.contextInitialized(event);
}
代码示例来源:origin: stackoverflow.com
MyDAO myDAO = null;
ServletContext servletContext = (ServletContext) context
.getMessageContext().get("javax.xml.ws.servlet.context");
WebApplicationContext webApplicationContext = WebApplicationContextUtils
.getRequiredWebApplicationContext(servletContext);
myDAO = (MyDAO) webApplicationContext
.getAutowireCapableBeanFactory().getBean("myDAO");
代码示例来源:origin: stackoverflow.com
public void init(FilterConfig filterConfig) throws ServletException {
ServletContext servletContext = filterConfig.getServletContext();
WebApplicationContext webApplicationContext =
WebApplicationContextUtils.getWebApplicationContext(servletContext);
AutowireCapableBeanFactory autowireCapableBeanFactory =
webApplicationContext.getAutowireCapableBeanFactory();
autowireCapableBeanFactory.configureBean(this, BEAN_NAME);
}
代码示例来源:origin: org.springframework/spring-webflow
protected AutowireCapableBeanFactory getBeanFactory() {
return WebApplicationContextUtils.getWebApplicationContext(
(ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext())
.getAutowireCapableBeanFactory();
}
代码示例来源:origin: org.onebusaway/onebusaway-presentation
public Component getBean(ValueStack stack, HttpServletRequest req,
HttpServletResponse res) {
ResourcesUrlComponent component = new ResourcesUrlComponent(stack);
WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(pageContext.getServletContext());
context.getAutowireCapableBeanFactory().autowireBean(component);
return component;
}
代码示例来源:origin: rancher/cattle
@Override
public void init(FilterConfig filterConfig) throws ServletException {
WebApplicationContextUtils
.getRequiredWebApplicationContext(filterConfig.getServletContext())
.getAutowireCapableBeanFactory()
.autowireBean(this);
}
内容来源于网络,如有侵权,请联系作者删除!