use of org.springframework.beans.factory.config.AutowireCapableBeanFactory in project grails-core by grails.
the class AbstractGrailsPluginManager method doRuntimeConfiguration.
/**
* Base implementation that simply goes through the list of plugins and calls doWithRuntimeConfiguration on each
* @param springConfig The RuntimeSpringConfiguration instance
*/
public void doRuntimeConfiguration(RuntimeSpringConfiguration springConfig) {
ApplicationContext context = springConfig.getUnrefreshedApplicationContext();
AutowireCapableBeanFactory autowireCapableBeanFactory = context.getAutowireCapableBeanFactory();
if (autowireCapableBeanFactory instanceof ConfigurableListableBeanFactory) {
ConfigurableListableBeanFactory beanFactory = (ConfigurableListableBeanFactory) autowireCapableBeanFactory;
ConversionService existingConversionService = beanFactory.getConversionService();
ConverterRegistry converterRegistry;
if (existingConversionService == null) {
GenericConversionService conversionService = new GenericConversionService();
converterRegistry = conversionService;
beanFactory.setConversionService(conversionService);
} else {
converterRegistry = (ConverterRegistry) existingConversionService;
}
converterRegistry.addConverter(new Converter<NavigableMap.NullSafeNavigator, Object>() {
@Override
public Object convert(NavigableMap.NullSafeNavigator source) {
return null;
}
});
}
checkInitialised();
for (GrailsPlugin plugin : pluginList) {
if (plugin.supportsCurrentScopeAndEnvironment() && plugin.isEnabled(context.getEnvironment().getActiveProfiles())) {
plugin.doWithRuntimeConfiguration(springConfig);
}
}
}
use of org.springframework.beans.factory.config.AutowireCapableBeanFactory in project otter by alibaba.
the class OtterDownStreamHandlerIntergration method testSimple.
@Test
public void testSimple() {
final OtterDownStreamHandler handler = new OtterDownStreamHandler();
handler.setPipelineId(388L);
handler.setDetectingIntervalInSeconds(1);
((AutowireCapableBeanFactory) TestedObject.getSpringBeanFactory()).autowireBeanProperties(handler, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false);
final CountDownLatch count = new CountDownLatch(1);
ExecutorService executor = Executors.newFixedThreadPool(1);
executor.submit(new Runnable() {
public void run() {
int times = 50;
handler.before(Arrays.asList(buildEvent()));
while (--times > 0) {
try {
Thread.sleep(50000);
} catch (InterruptedException e) {
}
handler.before(Arrays.asList(buildEvent()));
}
count.countDown();
}
});
try {
count.await();
} catch (InterruptedException e) {
}
}
use of org.springframework.beans.factory.config.AutowireCapableBeanFactory in project Settler by EmhyrVarEmreis.
the class AutowiringSpringBeanJobFactory method createJobInstance.
@Override
protected Object createJobInstance(final TriggerFiredBundle bundle) throws Exception {
Object job = super.createJobInstance(bundle);
AutowireCapableBeanFactory autowireCapableBeanFactory = applicationContext.getAutowireCapableBeanFactory();
autowireCapableBeanFactory.autowireBean(job);
job = autowireCapableBeanFactory.initializeBean(job, job.getClass().getName());
return job;
}
use of org.springframework.beans.factory.config.AutowireCapableBeanFactory in project cloudstack by apache.
the class ModuleBasedFilter method init.
@Override
public void init(FilterConfig filterConfig) throws ServletException {
String module = filterConfig.getInitParameter("module");
CloudStackSpringContext context = (CloudStackSpringContext) filterConfig.getServletContext().getAttribute(CloudStackSpringContext.CLOUDSTACK_CONTEXT_SERVLET_KEY);
if (context == null)
return;
ApplicationContext applicationContext = context.getApplicationContextForWeb(module);
if (applicationContext != null) {
AutowireCapableBeanFactory factory = applicationContext.getAutowireCapableBeanFactory();
if (factory != null) {
factory.autowireBean(this);
enabled = true;
}
}
}
use of org.springframework.beans.factory.config.AutowireCapableBeanFactory in project cloudstack by apache.
the class ComponentContext method initComponentsLifeCycle.
public static void initComponentsLifeCycle() {
if (!s_initializeBeans)
return;
AutowireCapableBeanFactory beanFactory = s_appContext.getAutowireCapableBeanFactory();
Map<String, ComponentMethodInterceptable> interceptableComponents = getApplicationContext().getBeansOfType(ComponentMethodInterceptable.class);
for (Map.Entry<String, ComponentMethodInterceptable> entry : interceptableComponents.entrySet()) {
Object bean = getTargetObject(entry.getValue());
beanFactory.configureBean(bean, entry.getKey());
}
Map<String, ComponentLifecycle> lifecycleComponents = getApplicationContext().getBeansOfType(ComponentLifecycle.class);
Map<String, ComponentLifecycle>[] classifiedComponents = new Map[ComponentLifecycle.MAX_RUN_LEVELS];
for (int i = 0; i < ComponentLifecycle.MAX_RUN_LEVELS; i++) {
classifiedComponents[i] = new HashMap<String, ComponentLifecycle>();
}
for (Map.Entry<String, ComponentLifecycle> entry : lifecycleComponents.entrySet()) {
classifiedComponents[entry.getValue().getRunLevel()].put(entry.getKey(), entry.getValue());
}
// Run the SystemIntegrityCheckers first
Map<String, SystemIntegrityChecker> integrityCheckers = getApplicationContext().getBeansOfType(SystemIntegrityChecker.class);
for (Entry<String, SystemIntegrityChecker> entry : integrityCheckers.entrySet()) {
s_logger.info("Running SystemIntegrityChecker " + entry.getKey());
try {
entry.getValue().check();
} catch (Throwable e) {
s_logger.error("System integrity check failed. Refuse to startup", e);
System.exit(1);
}
}
// configuration phase
Map<String, String> avoidMap = new HashMap<String, String>();
for (int i = 0; i < ComponentLifecycle.MAX_RUN_LEVELS; i++) {
for (Map.Entry<String, ComponentLifecycle> entry : classifiedComponents[i].entrySet()) {
ComponentLifecycle component = entry.getValue();
String implClassName = ComponentContext.getTargetClass(component).getName();
s_logger.info("Configuring " + implClassName);
if (avoidMap.containsKey(implClassName)) {
s_logger.info("Skip configuration of " + implClassName + " as it is already configured");
continue;
}
try {
component.configure(component.getName(), component.getConfigParams());
} catch (ConfigurationException e) {
s_logger.error("Unhandled exception", e);
throw new RuntimeException("Unable to configure " + implClassName, e);
}
avoidMap.put(implClassName, implClassName);
}
}
// starting phase
avoidMap.clear();
for (int i = 0; i < ComponentLifecycle.MAX_RUN_LEVELS; i++) {
for (Map.Entry<String, ComponentLifecycle> entry : classifiedComponents[i].entrySet()) {
ComponentLifecycle component = entry.getValue();
String implClassName = ComponentContext.getTargetClass(component).getName();
s_logger.info("Starting " + implClassName);
if (avoidMap.containsKey(implClassName)) {
s_logger.info("Skip configuration of " + implClassName + " as it is already configured");
continue;
}
try {
component.start();
if (getTargetObject(component) instanceof ManagementBean)
registerMBean((ManagementBean) getTargetObject(component));
} catch (Exception e) {
s_logger.error("Unhandled exception", e);
throw new RuntimeException("Unable to start " + implClassName, e);
}
avoidMap.put(implClassName, implClassName);
}
}
}
Aggregations