Example usage for org.springframework.beans.factory InitializingBean afterPropertiesSet

List of usage examples for org.springframework.beans.factory InitializingBean afterPropertiesSet

Introduction

In this page you can find the example usage for org.springframework.beans.factory InitializingBean afterPropertiesSet.

Prototype

void afterPropertiesSet() throws Exception;

Source Link

Document

Invoked by the containing BeanFactory after it has set all bean properties and satisfied BeanFactoryAware , ApplicationContextAware etc.

Usage

From source file:io.github.jhipster.async.ExceptionHandlingAsyncTaskExecutor.java

@Override
public void afterPropertiesSet() throws Exception {
    if (executor instanceof InitializingBean) {
        InitializingBean bean = (InitializingBean) executor;
        bean.afterPropertiesSet();
    }/*w  w  w  .  ja  v a 2 s  .co  m*/
}

From source file:org.guicerecipes.spring.SpringModule.java

@Override
protected void configure() {
    super.configure();

    bindAnnotationInjector(Autowired.class, AutowiredMemberProvider.class);

    // TODO cannot use the matchers to perform subclass checks!
    bindListener(Matchers.any(), new TypeListener() {
        public <I> void hear(TypeLiteral<I> injectableType, TypeEncounter<I> encounter) {
            Class<? super I> type = injectableType.getRawType();
            if (InitializingBean.class.isAssignableFrom(type)) {
                encounter.register(new InjectionListener<I>() {
                    public void afterInjection(I injectee) {
                        if (injectee instanceof InitializingBean) {
                            InitializingBean initializingBean = (InitializingBean) injectee;
                            try {
                                initializingBean.afterPropertiesSet();
                            } catch (Exception e) {
                                throw new ProvisionException("Failed to invoke afterPropertiesSet(): " + e, e);
                            }/*from w w  w  .j  a  v  a 2s  . co m*/
                        }
                    }
                });
            }
        }
    });

    bind(DisposableBeanCloser.class);
}

From source file:org.guiceyfruit.spring.SpringModule.java

protected void configure() {
    super.configure();

    bindAnnotationInjector(Autowired.class, AutowiredMemberProvider.class);

    // TODO cannot use the matchers to perform subclass checks!
    bindListener(Matchers.any(), new TypeListener() {
        public <I> void hear(TypeLiteral<I> injectableType, TypeEncounter<I> encounter) {
            Class<? super I> type = injectableType.getRawType();
            if (InitializingBean.class.isAssignableFrom(type)) {
                encounter.register(new InjectionListener<I>() {
                    public void afterInjection(I injectee) {
                        if (injectee instanceof InitializingBean) {
                            InitializingBean initializingBean = (InitializingBean) injectee;
                            try {
                                initializingBean.afterPropertiesSet();
                            } catch (Exception e) {
                                throw new ProvisionException("Failed to invoke afterPropertiesSet(): " + e, e);
                            }//from   w w  w  .  jav  a  2 s  . c o  m
                        }
                    }
                });
            }
        }
    });

    bind(DisposableBeanCloser.class);
}

From source file:org.brekka.stillingar.spring.snapshot.SnapshotDeltaValueInterceptor.java

protected void initializeBean(Object value) {
    if (value instanceof InitializingBean) {
        InitializingBean initializingBean = (InitializingBean) value;
        if (log.isInfoEnabled()) {
            log.info(String.format("Starting InitializingBean: %s", value));
        }/*from   w  ww  .j av  a2s . c om*/
        try {
            initializingBean.afterPropertiesSet();
        } catch (Exception e) {
            throw new ConfigurationException(String.format("Failed to initialize bean '%s'", value), e);
        }
    } else if (value instanceof Lifecycle) {
        Lifecycle lifecycle = (Lifecycle) value;
        if (log.isInfoEnabled()) {
            log.info(String.format("Starting Lifecycle bean: %s", value));
        }
        lifecycle.start();
    }
}

From source file:it.geosolutions.geostore.services.rest.impl.RESTMiscServiceImpl.java

@Override
public void reload(SecurityContext sc, String service) throws BadRequestWebEx {
    String reloadService = service;
    if (appContext != null) {
        if (!appContext.containsBean(reloadService)) {
            reloadService = reloadService + "Initializer";
        }//  w  ww.j av  a 2s.  c  o  m
        if (!appContext.containsBean(reloadService)) {
            throw new BadRequestWebEx("No service named " + service + " to reload");
        }
        InitializingBean bean = appContext.getBean(reloadService, InitializingBean.class);
        if (bean != null) {
            try {
                bean.afterPropertiesSet();
            } catch (Exception e) {
                throw new BadRequestWebEx(e.getMessage());
            }
        }
    }
}

From source file:org.springframework.ws.test.support.MockStrategiesHelper.java

/**
 * Returns a single strategy found in the given application context, or instantiates a default strategy if no
 * applicable strategy was found.//from   ww  w. ja va 2s .  c  om
 *
 * @param type the type of bean to be found in the application context
 * @param defaultType the type to instantiate and return when no bean of the specified type could be found
 * @return the bean found in the application context, or the default type if no bean of the given type can be found
 * @throws BeanInitializationException if there is more than 1 beans of the given type
 */
public <T, D extends T> T getStrategy(Class<T> type, Class<D> defaultType) {
    Assert.notNull(defaultType, "'defaultType' must not be null");
    T t = getStrategy(type);
    if (t != null) {
        return t;
    } else {
        if (logger.isDebugEnabled()) {
            logger.debug("No " + ClassUtils.getShortName(type) + " found, using default "
                    + ClassUtils.getShortName(defaultType));
        }
        T defaultStrategy = BeanUtils.instantiateClass(defaultType);
        if (defaultStrategy instanceof ApplicationContextAware) {
            ApplicationContextAware applicationContextAware = (ApplicationContextAware) defaultStrategy;
            applicationContextAware.setApplicationContext(applicationContext);
        }
        if (defaultStrategy instanceof InitializingBean) {
            InitializingBean initializingBean = (InitializingBean) defaultStrategy;
            try {
                initializingBean.afterPropertiesSet();
            } catch (Exception ex) {
                throw new BeanCreationException("Invocation of init method failed", ex);
            }
        }
        return defaultStrategy;
    }
}

From source file:software.coolstuff.springframework.owncloud.service.impl.local.OwncloudLocalFileTestExecutionListener.java

@Override
public void beforeTestMethod(TestContext testContext) throws Exception {
    if (isTestClassAssignableFromOwncloudLocalFileTest(testContext)) {
        ApplicationContext applicationContext = testContext.getApplicationContext();

        ResourceLoader resourceLoader = applicationContext;
        OwncloudProperties properties = applicationContext.getBean(OwncloudProperties.class);
        copyClasspathResourceToFile(resourceLoader, properties);

        InitializingBean localDataService = applicationContext.getBean(OwncloudLocalUserDataServiceImpl.class);
        localDataService.afterPropertiesSet();
    }//from w w  w . ja  v a2  s  .  c  o  m
}