List of usage examples for org.springframework.beans.factory.support GenericBeanDefinition setBeanClass
public void setBeanClass(@Nullable Class<?> beanClass)
From source file:com.laxser.blitz.web.impl.view.ViewDispatcherImpl.java
private VelocityViewResolver createVelocityViewResolver(Invocation inv, String beanName, String layoutUrl) throws MalformedURLException, IOException { if (SpringUtils.getBean(getApplicationContext(), VelocityConfig.class) == null) { URL propertiesLocation = inv.getServletContext().getResource("/WEB-INF/velocity.properties"); Properties velocityProperties = new Properties(); if (propertiesLocation != null) { InputStream is = propertiesLocation.openStream(); velocityProperties.load(is); is.close();/*w w w . j a va2 s . c o m*/ } if (StringUtils.isBlank(velocityProperties.getProperty("input.encoding"))) { velocityProperties.setProperty("input.encoding", "UTF-8"); } if (StringUtils.isBlank(velocityProperties.getProperty("output.encoding"))) { velocityProperties.setProperty("output.encoding", "UTF-8"); } GenericBeanDefinition beanDefinition = new GenericBeanDefinition(); beanDefinition.setBeanClass(BlitzVelocityConfigurer.class); MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.addPropertyValue(new PropertyValue("velocityProperties", velocityProperties)); propertyValues.addPropertyValue(new PropertyValue("resourceLoaderPath", "/")); beanDefinition.setPropertyValues(propertyValues); ((BeanDefinitionRegistry) getApplicationContext().getBeanFactory()) .registerBeanDefinition("velocityConfigurer", beanDefinition); logger.info("registered bean definition named" + " velocityConfigurer: " + BlitzVelocityConfigurer.class.getName()); } // GenericBeanDefinition beanDefinition = new GenericBeanDefinition(); MutablePropertyValues propertyValues = new MutablePropertyValues(); if (layoutUrl == null) { beanDefinition.setBeanClass(VelocityViewResolver.class); } else { beanDefinition.setBeanClass(VelocityLayoutViewResolver.class); propertyValues.addPropertyValue(new PropertyValue("layoutUrl", layoutUrl)); } propertyValues.addPropertyValue(new PropertyValue("contentType", "text/html;charset=UTF-8")); String toolboxConfigLocation = "/WEB-INF/velocity-toolbox.xml"; propertyValues.addPropertyValue(new PropertyValue("cache", Boolean.TRUE)); URL toolbox = inv.getServletContext().getResource(toolboxConfigLocation); if (toolbox == null) { toolboxConfigLocation = "/WEB-INF/toolbox.xml"; toolbox = inv.getServletContext().getResource(toolboxConfigLocation); } if (toolbox != null) { propertyValues.addPropertyValue(new PropertyValue("toolboxConfigLocation", toolboxConfigLocation)); } beanDefinition.setPropertyValues(propertyValues); ((BeanDefinitionRegistry) getApplicationContext().getBeanFactory()).registerBeanDefinition(beanName, beanDefinition); logger.info("registered bean definition named " + beanName + ": " + VelocityViewResolver.class.getName()); return (VelocityViewResolver) SpringUtils.getBean(getApplicationContext(), beanName); }
From source file:com.fitbur.testify.di.spring.SpringServiceLocator.java
@Override public void addService(Class<?> type) { GenericBeanDefinition bean = new GenericBeanDefinition(); bean.setBeanClass(type); bean.setRole(ROLE_APPLICATION);//ww w . j a va 2s . c om DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) context.getBeanFactory(); beanFactory.registerBeanDefinition(type.getSimpleName(), bean); }
From source file:com.fitbur.testify.di.spring.SpringServiceLocator.java
@Override public void addModule(Class<?> type) { GenericBeanDefinition bean = new GenericBeanDefinition(); bean.setBeanClass(type); bean.setRole(ROLE_APPLICATION);//from ww w .java 2s. c om DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) context.getBeanFactory(); beanFactory.registerBeanDefinition(type.getSimpleName(), bean); }
From source file:com.urbanmania.spring.beans.factory.config.annotations.PropertyAnnotationAndPlaceholderConfigurerTest.java
@Test public void testProcessPropertiesWithValue() { GenericBeanDefinition beanDefinition = new GenericBeanDefinition(); beanDefinition.setBeanClass(ValueTestBean.class); beanFactory.registerBeanDefinition(TEST_BEAN_NAME, beanDefinition); configurer.processProperties(beanFactory, properties); assertNotNull(// w w w . j av a 2s.c o m beanFactory.getBeanDefinition(TEST_BEAN_NAME).getPropertyValues().getPropertyValue("property")); assertEquals(TEST_DEFAULT_VALUE, beanFactory.getBeanDefinition(TEST_BEAN_NAME).getPropertyValues() .getPropertyValue("property").getValue()); }
From source file:com.urbanmania.spring.beans.factory.config.annotations.PropertyAnnotationAndPlaceholderConfigurerTest.java
@Test public void testProcessPropertiesWithDefaultValueWithFieldAnnotation() { GenericBeanDefinition beanDefinition = new GenericBeanDefinition(); beanDefinition.setBeanClass(AnnotatedFieldTestBean.class); beanFactory.registerBeanDefinition(TEST_BEAN_NAME, beanDefinition); configurer.processProperties(beanFactory, properties); assertNotNull(// w ww . j av a 2s.c o m beanFactory.getBeanDefinition(TEST_BEAN_NAME).getPropertyValues().getPropertyValue("property")); assertEquals(TEST_DEFAULT_VALUE, beanFactory.getBeanDefinition(TEST_BEAN_NAME).getPropertyValues() .getPropertyValue("property").getValue()); }
From source file:com.urbanmania.spring.beans.factory.config.annotations.PropertyAnnotationAndPlaceholderConfigurerTest.java
@Test public void testProcessPropertiesWithoutBasePackage() { configurer.setBasePackage("com.example"); GenericBeanDefinition beanDefinition = new GenericBeanDefinition(); beanDefinition.setBeanClass(SimplePropetyAnnotatedBean.class); beanFactory.registerBeanDefinition(TEST_BEAN_NAME, beanDefinition); properties.put(TEST_KEY, TEST_VALUE); configurer.processProperties(beanFactory, properties); assertTrue(beanFactory.getBeanDefinition(TEST_BEAN_NAME).getPropertyValues().isEmpty()); }
From source file:com.urbanmania.spring.beans.factory.config.annotations.PropertyAnnotationAndPlaceholderConfigurerTest.java
@Test public void testProcessPropertiesWithEmptyStringValue() throws Exception { GenericBeanDefinition beanDefinition = new GenericBeanDefinition(); beanDefinition.setBeanClass(EmptyStringValueTestBean.class); beanFactory.registerBeanDefinition(TEST_BEAN_NAME, beanDefinition); configurer.processProperties(beanFactory, properties); assertNotNull(// w ww.j a v a2s .c o m beanFactory.getBeanDefinition(TEST_BEAN_NAME).getPropertyValues().getPropertyValue("property")); assertEquals("", beanFactory.getBeanDefinition(TEST_BEAN_NAME).getPropertyValues() .getPropertyValue("property").getValue()); }
From source file:com.urbanmania.spring.beans.factory.config.annotations.PropertyAnnotationAndPlaceholderConfigurerTest.java
@Test public void testPropertyAnnotationWithNoKeyOrValue() throws Exception { GenericBeanDefinition beanDefinition = new GenericBeanDefinition(); beanDefinition.setBeanClass(PropertyWithNoKeyOrValueAnnotationBean.class); beanFactory.registerBeanDefinition(TEST_BEAN_NAME, beanDefinition); configurer.processProperties(beanFactory, properties); assertNotNull(//from w w w .ja va2 s . c om beanFactory.getBeanDefinition(TEST_BEAN_NAME).getPropertyValues().getPropertyValue("property")); assertEquals("", beanFactory.getBeanDefinition(TEST_BEAN_NAME).getPropertyValues() .getPropertyValue("property").getValue()); }
From source file:com.urbanmania.spring.beans.factory.config.annotations.PropertyAnnotationAndPlaceholderConfigurerTest.java
@Test public void testProcessPropertiesWithPlaceholderSubstitution() { GenericBeanDefinition beanDefinition = new GenericBeanDefinition(); beanDefinition.setBeanClass(PlaceholderValueTestBean.class); beanFactory.registerBeanDefinition(TEST_BEAN_NAME, beanDefinition); properties.put(TEST_KEY, TEST_VALUE); configurer.processProperties(beanFactory, properties); assertNotNull(/*from w ww.ja v a 2s.c o m*/ beanFactory.getBeanDefinition(TEST_BEAN_NAME).getPropertyValues().getPropertyValue("property")); assertEquals("testValue-testValue", beanFactory.getBeanDefinition(TEST_BEAN_NAME).getPropertyValues() .getPropertyValue("property").getValue()); }