Java Code Examples for org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor#processInjection()

The following examples show how to use org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor#processInjection() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SpringBeanAutowiringSupport.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * 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.");
		}
	}
}
 
Example 2
Source File: SpringBeanAutowiringSupport.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * 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.");
		}
	}
}
 
Example 3
Source File: SpringBeanAutowiringSupport.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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.");
		}
	}
}
 
Example 4
Source File: SpringBeanAutowiringSupport.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * 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.");
		}
	}
}
 
Example 5
Source File: SpringBeanAutowiringInterceptor.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Actually autowire the target bean after construction/passivation.
 * @param target the target bean to autowire
 */
protected void doAutowireBean(Object target) {
	AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
	configureBeanPostProcessor(bpp, target);
	bpp.setBeanFactory(getBeanFactory(target));
	bpp.processInjection(target);
}
 
Example 6
Source File: SpringBeanAutowiringInterceptor.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Actually autowire the target bean after construction/passivation.
 * @param target the target bean to autowire
 */
protected void doAutowireBean(Object target) {
	AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
	configureBeanPostProcessor(bpp, target);
	bpp.setBeanFactory(getBeanFactory(target));
	bpp.processInjection(target);
}
 
Example 7
Source File: UserRegistrationSteps.java    From user-registration-V2 with Apache License 2.0 5 votes vote down vote up
public UserRegistrationSteps() {
	super();
	SpringApplication application = new SpringApplication(
			RegistrationApplication.class);
	application.setWebEnvironment(false);
	AutowiredAnnotationBeanPostProcessor autowiredAnnotationBeanPostProcessor = new AutowiredAnnotationBeanPostProcessor();
	autowiredAnnotationBeanPostProcessor.setBeanFactory(application.run()
			.getBeanFactory());
	autowiredAnnotationBeanPostProcessor.processInjection(this);
}
 
Example 8
Source File: UserRegistrationSteps.java    From user-registration-V2 with Apache License 2.0 5 votes vote down vote up
public UserRegistrationSteps() {
	super();
	SpringApplication application = new SpringApplication(
			RegistrationApplication.class);
	application.setWebEnvironment(false);
	AutowiredAnnotationBeanPostProcessor autowiredAnnotationBeanPostProcessor = new AutowiredAnnotationBeanPostProcessor();
	autowiredAnnotationBeanPostProcessor.setBeanFactory(application.run()
			.getBeanFactory());
	autowiredAnnotationBeanPostProcessor.processInjection(this);
}
 
Example 9
Source File: TasksRunnerService.java    From redisson with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
private <T> T decode(TaskParameters params) {
    ByteBuf classBodyBuf = Unpooled.wrappedBuffer(params.getClassBody());
    ByteBuf stateBuf = Unpooled.wrappedBuffer(params.getState());
    try {
        HashValue hash = new HashValue(Hash.hash128(classBodyBuf));
        Codec classLoaderCodec = CODECS.get(hash);
        if (classLoaderCodec == null) {
            RedissonClassLoader cl = new RedissonClassLoader(codec.getClassLoader());
            cl.loadClass(params.getClassName(), params.getClassBody());
            
            classLoaderCodec = this.codec.getClass().getConstructor(ClassLoader.class).newInstance(cl);
            CODECS.put(hash, classLoaderCodec);
        }
        
        T task;
        if (params.getLambdaBody() != null) {
            ByteArrayInputStream is = new ByteArrayInputStream(params.getLambdaBody());
            
            //set thread context class loader to be the classLoaderCodec.getClassLoader() variable as there could be reflection
            //done while reading from input stream which reflection will use thread class loader to load classes on demand
            ClassLoader currentThreadClassLoader = Thread.currentThread().getContextClassLoader();                
            try {
                Thread.currentThread().setContextClassLoader(classLoaderCodec.getClassLoader());
                ObjectInput oo = new CustomObjectInputStream(classLoaderCodec.getClassLoader(), is);
                task = (T) oo.readObject();
                oo.close();
            } finally {
                Thread.currentThread().setContextClassLoader(currentThreadClassLoader);
            }
        } else {
            task = (T) classLoaderCodec.getValueDecoder().decode(stateBuf, null);
        }

        Injector.inject(task, RedissonClient.class, redisson);
        Injector.inject(task, String.class, params.getRequestId());
        
        if (beanFactory != null) {
            AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
            bpp.setBeanFactory(beanFactory);
            bpp.processInjection(task);
        }
        
        return task;
    } catch (Exception e) {
        throw new IllegalStateException("Unable to initialize codec with ClassLoader parameter", e);
    } finally {
        classBodyBuf.release();
        stateBuf.release();
    }
}
 
Example 10
Source File: SpringBeanAutowiringSupport.java    From spring-analysis-note with MIT License 3 votes vote down vote up
/**
 * 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);
}
 
Example 11
Source File: SpringBeanAutowiringSupport.java    From java-technology-stack with MIT License 3 votes vote down vote up
/**
 * 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);
}
 
Example 12
Source File: SpringBeanAutowiringSupport.java    From lams with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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);
}
 
Example 13
Source File: SpringBeanAutowiringSupport.java    From spring4-understanding with Apache License 2.0 3 votes vote down vote up
/**
 * 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);
}