use of org.springframework.beans.factory.BeanFactory in project geronimo-xbean by apache.
the class JndiTest method testConfigureJndiInsideSpringXml.
public void testConfigureJndiInsideSpringXml() throws Exception {
// lets load a spring context
BeanFactory factory = new ClassPathXmlApplicationContext("org/apache/xbean/spring/jndi/spring.xml");
Object test = factory.getBean("restaurant");
assertNotNull("Should have found the test object", test);
Object jndi = factory.getBean("jndi");
assertNotNull("Should have found the jndi object", jndi);
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, SpringInitialContextFactory.class.getName());
InitialContext context = new InitialContext(env);
assertEntryExists(context, "test");
assertEntryExists(context, "test/restaurant");
assertSame(test, context.lookup("test/restaurant"));
}
use of org.springframework.beans.factory.BeanFactory in project pentaho-platform by pentaho.
the class DefaultPluginManager method getNativeBeanFactory.
/**
* The native bean factory is the bean factory that has had all of its bean definitions loaded natively. In other
* words, the plugin manager will not add any further bean definitions (i.e. from a plugin.xml file) into this
* factory. This factory represents the one responsible for holding bean definitions for plugin.spring.xml or, if in a
* unit test environment, the unit test pre-loaded bean factory.
*
* @return a bean factory will preconfigured bean definitions or <code>null</code> if no bean definition source is
* available
*/
protected BeanFactory getNativeBeanFactory(final IPlatformPlugin plugin, final ClassLoader loader) {
BeanFactory nativeFactory = null;
if (plugin.getBeanFactory() != null) {
// then we are probably in a unit test so just use the preconfigured one
BeanFactory testFactory = plugin.getBeanFactory();
if (testFactory instanceof ConfigurableBeanFactory) {
((ConfigurableBeanFactory) testFactory).setBeanClassLoader(loader);
} else {
// $NON-NLS-1$
logger.warn(Messages.getInstance().getString("PluginManager.WARN_WRONG_BEAN_FACTORY_TYPE"));
}
nativeFactory = testFactory;
} else {
// $NON-NLS-1$
File f = new File(((PluginClassLoader) loader).getPluginDir(), "plugin.spring.xml");
if (f.exists()) {
// $NON-NLS-1$
logger.debug("Found plugin spring file @ " + f.getAbsolutePath());
FileSystemResource fsr = new FileSystemResource(f);
GenericApplicationContext appCtx = new GenericApplicationContext() {
@Override
protected void prepareBeanFactory(ConfigurableListableBeanFactory clBeanFactory) {
super.prepareBeanFactory(clBeanFactory);
clBeanFactory.setBeanClassLoader(loader);
}
@Override
public ClassLoader getClassLoader() {
return loader;
}
};
XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(appCtx);
xmlReader.setBeanClassLoader(loader);
xmlReader.loadBeanDefinitions(fsr);
nativeFactory = appCtx;
}
}
return nativeFactory;
}
use of org.springframework.beans.factory.BeanFactory in project pentaho-platform by pentaho.
the class PentahoSystemPluginManager method createBeanFactory.
private GenericApplicationContext createBeanFactory(IPlatformPlugin plugin, ClassLoader classloader) throws PlatformPluginRegistrationException {
if (!(classloader instanceof PluginClassLoader)) {
throw new PlatformPluginRegistrationException("Can't determine plugin dir to load spring file because classloader is not of type PluginClassLoader. " + "This is since we are probably in a unit test");
}
//
// Get the native factory (the factory that comes preconfigured via either Spring bean files or via JUnit test
//
BeanFactory nativeBeanFactory = getNativeBeanFactory(plugin, classloader);
//
// Now create the definable factory for accepting old style bean definitions from IPluginProvider
//
GenericApplicationContext beanFactory = null;
if (nativeBeanFactory != null && nativeBeanFactory instanceof GenericApplicationContext) {
beanFactory = (GenericApplicationContext) nativeBeanFactory;
} else {
beanFactory = new GenericApplicationContext();
beanFactory.setClassLoader(classloader);
beanFactory.getBeanFactory().setBeanClassLoader(classloader);
if (nativeBeanFactory != null) {
beanFactory.getBeanFactory().setParentBeanFactory(nativeBeanFactory);
}
}
beanFactory.addBeanFactoryPostProcessor(new PentahoBeanScopeValidatorPostProcessor());
// been made available to the plugin manager
for (PluginBeanDefinition def : plugin.getBeans()) {
// register by classname if id is null
def.setBeanId((def.getBeanId() == null) ? def.getClassname() : def.getBeanId());
try {
assertUnique(beanFactory, plugin.getId(), def.getBeanId());
} catch (PlatformPluginRegistrationException e) {
logger.error(MessageFormat.format("Unable to register plugin bean, a bean by the id {0} is already defined in plugin: {1}", def.getBeanId(), plugin.getId()));
continue;
}
// defining plugin beans the old way through the plugin provider ifc supports only prototype scope
BeanDefinition beanDef = BeanDefinitionBuilder.rootBeanDefinition(def.getClassname()).setScope(BeanDefinition.SCOPE_PROTOTYPE).getBeanDefinition();
beanFactory.registerBeanDefinition(def.getBeanId(), beanDef);
}
return beanFactory;
}
use of org.springframework.beans.factory.BeanFactory in project spring-cloud-sleuth by spring-cloud.
the class TraceableExecutorServiceTests method should_propagate_trace_info_when_compleable_future_is_used.
@Test
public void should_propagate_trace_info_when_compleable_future_is_used() throws Exception {
ExecutorService executorService = this.executorService;
BeanFactory beanFactory = beanFactory();
// tag::completablefuture[]
CompletableFuture<Long> completableFuture = CompletableFuture.supplyAsync(() -> {
// perform some logic
return 1_000_000L;
}, new TraceableExecutorService(beanFactory, executorService, // 'calculateTax' explicitly names the span - this param is optional
"calculateTax"));
// end::completablefuture[]
then(completableFuture.get()).isEqualTo(1_000_000L);
then(this.tracer.currentSpan()).isNull();
}
use of org.springframework.beans.factory.BeanFactory in project com.revolsys.open by revolsys.
the class BeanReferenceListFactoryBean method createInstance.
@Override
protected List<T> createInstance() throws Exception {
final BeanFactory beanFactory = getBeanFactory();
final List<T> beans = new ArrayList<>();
for (int i = 0; i < this.beanNames.size(); i++) {
final String beanName = this.beanNames.get(i);
final T bean = (T) beanFactory.getBean(beanName);
beans.add(bean);
}
return beans;
}
Aggregations