List of usage examples for org.springframework.beans.factory.support RootBeanDefinition RootBeanDefinition
public RootBeanDefinition(String beanClassName, ConstructorArgumentValues cargs, MutablePropertyValues pvs)
From source file:com.github.wnameless.spring.bulkapi.BulkApiConfig.java
@Override public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException { BeanDefinition ctrlBeanDef = new RootBeanDefinition(BulkApiController.class, Autowire.BY_TYPE.value(), true);// ww w.ja v a2 s . c o m registry.registerBeanDefinition("bulkApiController", ctrlBeanDef); BeanDefinition adviceBeanDef = new RootBeanDefinition(BulkApiExceptionHandlerAdvice.class, Autowire.BY_TYPE.value(), true); registry.registerBeanDefinition("bulkApiExceptionHandlerAdvice", adviceBeanDef); }
From source file:com.gwtplatform.dispatch.rpc.server.spring.utils.SpringUtils.java
private static <B> RootBeanDefinition createBeanDefinition(B instance) { RootBeanDefinition bd = new RootBeanDefinition(instance.getClass(), AbstractBeanDefinition.AUTOWIRE_CONSTRUCTOR, false); bd.setScope(BeanDefinition.SCOPE_SINGLETON); return bd;//from w ww .j a va 2 s.c om }
From source file:org.owasp.webgoat.plugins.PluginEndpointPublisher.java
private void publishEndpoint(Class<? extends MvcEndpoint> e) { try {/*from www . ja v a2 s . c o m*/ BeanDefinition beanDefinition = new RootBeanDefinition(e, Autowire.BY_TYPE.value(), true); DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) applicationContext .getBeanFactory(); beanFactory.registerBeanDefinition(beanDefinition.getBeanClassName(), beanDefinition); } catch (Exception ex) { log.error("Failed to register " + e.getSimpleName() + " as endpoint with Spring, skipping..."); } }
From source file:ro.pippo.spring.SpringControllerFactory.java
/** * Created a bean definition for a class. * Optionally configure all bean properties, like scope, prototype/singleton, etc using: * <p/>//from w ww. j ava2 s. com * <pre> * BeanDefinition definition = super.createBeanDefinition(beanClass); * definition.setScope(BeanDefinition.SCOPE_SINGLETON); * return definition; * </pre> * * @param controllerClass * @return */ protected BeanDefinition createBeanDefinition(Class<? extends Controller> controllerClass) { // optionally configure all bean properties, like scope, prototype/singleton, etc // return new RootBeanDefinition(beanClass); return new RootBeanDefinition(controllerClass, Autowire.BY_TYPE.value(), true); }
From source file:com.griddynamics.banshun.config.xml.ExportBeanDefinitionParser.java
/** * Creates a {@link ExportRef} bean definition. *///from w ww . jav a 2 s .c o m private BeanDefinition defineExportRef(String serviceName, Class<?> serviceIface, String beanName) { return new RootBeanDefinition(ExportRef.class, defineExportRefConstructorArgs(serviceName, serviceIface, beanName), null); }
From source file:hudson.util.spring.DefaultBeanConfiguration.java
protected AbstractBeanDefinition createBeanDefinition() { AbstractBeanDefinition bd;/* www .ja va 2 s.c o m*/ if (constructorArgs.size() > 0) { ConstructorArgumentValues cav = new ConstructorArgumentValues(); for (Object constructorArg : constructorArgs) { cav.addGenericArgumentValue(constructorArg); } if (StringUtils.isBlank(parentName)) { bd = new RootBeanDefinition(clazz, cav, null); } else { bd = new ChildBeanDefinition(parentName, clazz, cav, null); } bd.setSingleton(singleton); } else { if (StringUtils.isBlank(parentName)) { bd = new RootBeanDefinition(clazz, singleton); } else { bd = new ChildBeanDefinition(parentName, clazz, null, null); bd.setSingleton(singleton); } } wrapper = new BeanWrapperImpl(bd); return bd; }
From source file:org.exoplatform.container.spring.SpringContainer.java
/** * {@inheritDoc}/*from w w w . ja v a2s . c o m*/ */ @Override @SuppressWarnings({ "rawtypes", "unchecked" }) public void start() { ConfigurationManager cm = super.getComponentInstanceOfType(ConfigurationManager.class, false); // We check if the component has been defined in the configuration of the current container // The goal is to enable the SpringContainer only if it is needed Component component = cm.getComponent(ApplicationContextProvider.class); if (component == null) { if (LOG.isDebugEnabled()) { LOG.debug( "No ApplicationContextProvider has been defined, thus the SpringContainer will be disabled." + " To enable the Spring Integration please define an ApplicationContextProvider"); } } else { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); bf.setAutowireCandidateResolver(new QualifierAnnotationAutowireCandidateResolver()); Collection<ComponentAdapter<?>> adapters = delegate.getComponentAdapters(); for (ComponentAdapter<?> adapter : adapters) { Object key = adapter.getComponentKey(); String name = keyToBeanName(key); String factoryName = name + "#factory"; RootBeanDefinition def = new RootBeanDefinition(adapter.getComponentImplementation(), AbstractBeanDefinition.AUTOWIRE_NO, false); def.setScope(BeanDefinition.SCOPE_PROTOTYPE); def.setFactoryBeanName(factoryName); def.setFactoryMethodName("getInstance"); def.setLazyInit(true); def.setTargetType(adapter.getComponentImplementation()); if (key instanceof String) { def.addQualifier(new AutowireCandidateQualifier(Named.class, key)); } else if (key instanceof Class<?> && ((Class<?>) key).isAnnotation()) { def.addQualifier(new AutowireCandidateQualifier((Class<?>) key)); } else { def.setPrimary(true); } bf.registerBeanDefinition(name, def); bf.registerSingleton(factoryName, new ComponentAdapterFactoryBean(adapter)); } GenericApplicationContext parentContext = new GenericApplicationContext(bf); parentContext.refresh(); ApplicationContextProvider provider = super.getComponentInstanceOfType(ApplicationContextProvider.class, false); ctx = provider.getApplicationContext(parentContext); LOG.info("A SpringContainer has been enabled using the ApplicationContextProvider " + provider.getClass()); } super.start(); }
From source file:ome.client.utests.Preferences3Test.java
@Test public void test_makeOurOwnDefault() throws Exception { // Others:/*from w w w. j a va 2 s . c om*/ // new ManagedMap(); // BeanWrapper bw = new BeanWrapperImpl( defaultMap ); Map defaultMap = new HashMap(); defaultMap.put("omero.user", "foo"); ConstructorArgumentValues cav = new ConstructorArgumentValues(); cav.addGenericArgumentValue(defaultMap); BeanDefinition def = new RootBeanDefinition(HashMap.class, cav, null); StaticApplicationContext ac = new StaticApplicationContext(); ac.registerBeanDefinition("map", def); ac.refresh(); ConstructorArgumentValues testCav = new ConstructorArgumentValues(); testCav.addGenericArgumentValue(new RuntimeBeanReference("map")); BeanDefinition testDef = new RootBeanDefinition(HashMap.class, testCav, null); StaticApplicationContext defaultTest = new StaticApplicationContext(ac); defaultTest.registerBeanDefinition("test", testDef); defaultTest.refresh(); assertTrue("foo".equals(((Map) defaultTest.getBean("test")).get("omero.user"))); }
From source file:ome.client.utests.Preferences3Test.java
@Test public void test_makeOurOwnRuntime() throws Exception { // use properties // if no Properties given, then is static (global) Map runtimeMap = new HashMap(); runtimeMap.put("omero.user", "bar"); ConstructorArgumentValues cav2 = new ConstructorArgumentValues(); cav2.addGenericArgumentValue(runtimeMap); BeanDefinition def2 = new RootBeanDefinition(HashMap.class, cav2, null); StaticApplicationContext ac2 = new StaticApplicationContext(); ac2.registerBeanDefinition("map", def2); ac2.refresh();//ww w. j av a2s.c om ConstructorArgumentValues testCav2 = new ConstructorArgumentValues(); testCav2.addGenericArgumentValue(new RuntimeBeanReference("map")); BeanDefinition testDef2 = new RootBeanDefinition(HashMap.class, testCav2, null); StaticApplicationContext defaultTest2 = new StaticApplicationContext(ac2); defaultTest2.registerBeanDefinition("test", testDef2); defaultTest2.refresh(); assertTrue("bar".equals(((Map) defaultTest2.getBean("test")).get("omero.user"))); }
From source file:ome.client.utests.Preferences3Test.java
@Test(groups = "ticket:1058") public void testOmeroUserIsProperlySetWithSpring2_5_5Manual() { Server s = new Server("localhost", 1099); Login l = new Login("me", "password"); Properties p = s.asProperties(); p.putAll(l.asProperties());// w ww .j a v a2s .c o m // This is copied from OmeroContext. This is the parent context which // should contain the properties; Properties copy = new Properties(p); ConstructorArgumentValues ctorArg1 = new ConstructorArgumentValues(); ctorArg1.addGenericArgumentValue(copy); BeanDefinition definition1 = new RootBeanDefinition(Properties.class, ctorArg1, null); StaticApplicationContext staticContext = new StaticApplicationContext(); staticContext.registerBeanDefinition("properties", definition1); staticContext.refresh(); // This is the child context and contains a definition of a // PlaceHolderConfigurer // as well as a user of StaticApplicationContext childContext = new StaticApplicationContext(); MutablePropertyValues mpv2 = new MutablePropertyValues(); mpv2.addPropertyValue("properties", new RuntimeBeanReference("properties")); mpv2.addPropertyValue("systemPropertiesModeName", "SYSTEM_PROPERTIES_MODE_FALLBACK"); mpv2.addPropertyValue("localOverride", "true"); BeanDefinition definitionConfigurer = new RootBeanDefinition(PreferencesPlaceholderConfigurer.class, null, mpv2); childContext.registerBeanDefinition("propertiesPlaceholderConfigurer", definitionConfigurer); ConstructorArgumentValues cav2 = new ConstructorArgumentValues(); cav2.addGenericArgumentValue("${omero.user}"); BeanDefinition definitionTest = new RootBeanDefinition(String.class, cav2, null); childContext.registerBeanDefinition("test", definitionTest); childContext.setParent(staticContext); childContext.refresh(); String test = (String) childContext.getBean("test"); assertEquals(test, "me"); }