List of usage examples for org.springframework.beans.factory.support GenericBeanDefinition setBeanClass
public void setBeanClass(@Nullable Class<?> beanClass)
From source file:org.mybatis.spring.mapper.MapperScannerConfigurerTest.java
@Before public void setupContext() { applicationContext = new GenericApplicationContext(); // add the mapper scanner as a bean definition rather than explicitly setting a // postProcessor on the context so initialization follows the same code path as reading from // an XML config file GenericBeanDefinition definition = new GenericBeanDefinition(); definition.setBeanClass(MapperScannerConfigurer.class); definition.getPropertyValues().add("basePackage", "org.mybatis.spring.mapper"); applicationContext.registerBeanDefinition("mapperScanner", definition); setupSqlSessionFactory("sqlSessionFactory"); // assume support for autowiring fields is added by MapperScannerConfigurer via // org.springframework.context.annotation.ClassPathBeanDefinitionScanner.includeAnnotationConfig }
From source file:org.mybatis.spring.mapper.MapperScannerConfigurerTest.java
@Test public void testNameGenerator() { GenericBeanDefinition definition = new GenericBeanDefinition(); definition.setBeanClass(BeanNameGenerator.class); applicationContext.registerBeanDefinition("beanNameGenerator", definition); applicationContext.getBeanDefinition("mapperScanner").getPropertyValues().add("nameGenerator", new RuntimeBeanReference("beanNameGenerator")); startContext();/*from ww w . j a va 2 s. c o m*/ // only child inferfaces should be loaded and named with its class name applicationContext.getBean(MapperInterface.class.getName()); applicationContext.getBean(MapperSubinterface.class.getName()); applicationContext.getBean(MapperChildInterface.class.getName()); applicationContext.getBean(AnnotatedMapper.class.getName()); }
From source file:com.longio.spring.LioBootstrap.java
private void bootEndpoints(DefaultListableBeanFactory bf, String name) { RootBeanDefinition bd = (RootBeanDefinition) bf.getBeanDefinition(name); String fbMethod = bd.getFactoryMethodName(); String fbName = bd.getFactoryBeanName(); Object fb = bf.getBean(fbName); if (!bf.containsBeanDefinition("longio.connector")) { GenericBeanDefinition bdd = new GenericBeanDefinition(); bdd.setBeanClass(NettyConnector.class); bf.registerBeanDefinition("longio.connector", bdd); }/* w ww . j a v a 2 s . co m*/ Connector connector = bf.getBean("longio.connector", Connector.class); Class<?> fbCls = fb.getClass().getSuperclass(); Method m; try { m = fbCls.getDeclaredMethod(fbMethod); Boots boots = m.getAnnotation(Boots.class); if (boots == null) { MethodDispatcher dispatcher = new MethodDispatcher(); Boot b = m.getAnnotation(Boot.class); connector.start(b.port(), dispatcher, b.tt(), b.pt(), b.pkg()); logger.info("connector start at port [" + b.port() + "] with tt = " + b.tt() + " and pt = " + b.pt() + " for pkg = " + b.pkg()); } else { for (Boot b : boots.value()) { MethodDispatcher dispatcher = new MethodDispatcher(); connector.start(b.port(), dispatcher, b.tt(), b.pt(), b.pkg()); logger.info("connector start at port [" + b.port() + "] with tt = " + b.tt() + " and pt = " + b.pt() + " for pkg = " + b.pkg()); } } } catch (Exception e) { e.printStackTrace(); } }
From source file:org.mybatis.spring.mapper.MapperScannerConfigurerTest.java
@Test public void testScanWithExplicitSqlSessionFactoryViaPlaceholder() throws Exception { setupSqlSessionFactory("sqlSessionFactory2"); // use a property placeholder for the session factory name applicationContext.getBeanDefinition("mapperScanner").getPropertyValues().add("sqlSessionFactoryBeanName", "${sqlSessionFactoryBeanNameProperty}"); Properties props = new java.util.Properties(); props.put("sqlSessionFactoryBeanNameProperty", "sqlSessionFactory2"); GenericBeanDefinition propertyDefinition = new GenericBeanDefinition(); propertyDefinition.setBeanClass(PropertyPlaceholderConfigurer.class); propertyDefinition.getPropertyValues().add("properties", props); applicationContext.registerBeanDefinition("propertiesPlaceholder", propertyDefinition); testInterfaceScan();/* w w w . j a v a2 s . c o m*/ }
From source file:com.laxser.blitz.web.impl.view.ViewDispatcherImpl.java
protected ViewResolver getJspViewResolver() throws IOException { if (this.jspViewResolver != null) { return this.jspViewResolver; }//w w w . j a va 2 s . co m String beanName = "jspViewResolver"; this.jspViewResolver = (ViewResolver) SpringUtils.getBean(getApplicationContext(), beanName); if (jspViewResolver == null) { GenericBeanDefinition beanDefinition = new GenericBeanDefinition(); beanDefinition.setBeanClass(InternalResourceViewResolver.class); MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.addPropertyValue(new PropertyValue("viewClass", JstlView.class)); beanDefinition.setPropertyValues(propertyValues); ((BeanDefinitionRegistry) getApplicationContext().getBeanFactory()).registerBeanDefinition(beanName, beanDefinition); logger.info("registered bean definition named " + beanName + ": " + InternalResourceViewResolver.class.getName()); jspViewResolver = (ViewResolver) SpringUtils.getBean(getApplicationContext(), beanName); } return this.jspViewResolver; }
From source file:org.mybatis.spring.mapper.MapperScannerConfigurerTest.java
@Test public void testScanWithPropertyPlaceholders() { GenericBeanDefinition definition = (GenericBeanDefinition) applicationContext .getBeanDefinition("mapperScanner"); // use a property placeholder for basePackage definition.getPropertyValues().removePropertyValue("basePackage"); definition.getPropertyValues().add("basePackage", "${basePackageProperty}"); definition.getPropertyValues().add("processPropertyPlaceHolders", true); // also use a property placeholder for an SqlSessionFactory property // to make sure the configLocation was setup correctly and MapperScanner did not change // regular property placeholder substitution definition = (GenericBeanDefinition) applicationContext.getBeanDefinition("sqlSessionFactory"); definition.getPropertyValues().removePropertyValue("configLocation"); definition.getPropertyValues().add("configLocation", "${configLocationProperty}"); Properties props = new java.util.Properties(); props.put("basePackageProperty", "org.mybatis.spring.mapper"); props.put("configLocationProperty", "classpath:org/mybatis/spring/mybatis-config.xml"); GenericBeanDefinition propertyDefinition = new GenericBeanDefinition(); propertyDefinition.setBeanClass(PropertyPlaceholderConfigurer.class); propertyDefinition.getPropertyValues().add("properties", props); applicationContext.registerBeanDefinition("propertiesPlaceholder", propertyDefinition); testInterfaceScan();//from w ww . jav a 2 s . com // make sure the configLocation was setup correctly // mybatis-config.xml changes the executor from the default SIMPLE type SqlSessionFactory sessionFactory = (SqlSessionFactory) applicationContext.getBean("sqlSessionFactory"); assertSame(ExecutorType.REUSE, sessionFactory.getConfiguration().getDefaultExecutorType()); }
From source file:com.sinosoft.one.mvc.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 ww. ja va 2 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(MvcVelocityConfigurer.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: " + MvcVelocityConfigurer.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:net.paoding.rose.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();/*from w w w. j a v a 2s . c om*/ } 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(RoseVelocityConfigurer.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: " + RoseVelocityConfigurer.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); }