List of usage examples for org.springframework.beans.factory.config BeanDefinition getBeanClassName
@Nullable String getBeanClassName();
From source file:com.newtranx.util.cassandra.spring.AccessorScannerConfigurer.java
@Override public void postProcessBeanFactory(ConfigurableListableBeanFactory context) throws BeansException { ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider( false) {/* w ww .ja va 2 s . co m*/ @Override protected boolean isCandidateComponent(AnnotatedBeanDefinition beanDefinition) { return beanDefinition.getMetadata().isInterface(); } }; scanner.addIncludeFilter(new AnnotationTypeFilter(Accessor.class)); for (BeanDefinition bd : scanner.findCandidateComponents(basePackage)) { Class<?> accessorCls; try { accessorCls = Class.forName(bd.getBeanClassName()); } catch (ClassNotFoundException e) { throw new AssertionError(e); } log.info("Creating proxy accessor: " + accessorCls.getName()); MethodInterceptor interceptor = new MethodInterceptor() { private final Lazy<?> target = new Lazy<>(() -> { log.info("Creating actual accessor: " + accessorCls.getName()); Session session; if (AccessorScannerConfigurer.this.session == null) session = mainContext.getBean(Session.class); else session = AccessorScannerConfigurer.this.session; MappingManager mappingManager = new MappingManager(session); return mappingManager.createAccessor(accessorCls); }); @Override public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable { if ("toString".equals(method.getName())) { return accessorCls.getName(); } return method.invoke(target.get(), args); } }; Enhancer enhancer = new Enhancer(); enhancer.setInterfaces(new Class<?>[] { accessorCls }); enhancer.setCallback(interceptor); Object bean = enhancer.create(); String beanName = StringUtils.uncapitalize(accessorCls.getSimpleName()); context.registerSingleton(beanName, bean); log.info("Bean registed, name=" + beanName + ", bean=" + bean.toString()); } }
From source file:com.github.bjoern2.yolotyrion.spring.xml.RepositorySingleBeanDefinitionParser.java
@Override public BeanDefinition parse(Element element, ParserContext parserContext) { // Scan classpath: String basePackage = element.getAttribute("basePackage"); // Scan for TemplateRepositories ClassPathScanningCandidateComponentProvider provider = generateScanner(TemplateRepository.class); Set<BeanDefinition> candidates = provider.findCandidateComponents(basePackage); for (BeanDefinition candidate : candidates) { BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(TemplateRepoFactoryBean.class); builder.addPropertyValue("repositoryInterface", candidate.getBeanClassName()); builder.addPropertyValue("handler", new TemplateRepositoryInvocationHandler()); AbstractBeanDefinition def = builder.getRawBeanDefinition(); String beanName = buildDefaultBeanName(def); registerBean(def, beanName, parserContext); }/* w w w .j a va 2 s. c om*/ // Scan for PropertyRepositories provider = generateScanner(PropertyRepository.class); candidates = provider.findCandidateComponents(basePackage); for (BeanDefinition candidate : candidates) { BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(PropertyRepoFactoryBean.class); builder.addPropertyValue("repositoryInterface", candidate.getBeanClassName()); builder.addPropertyValue("handler", new PropertyRepositoryInvocationHandler()); AbstractBeanDefinition def = builder.getRawBeanDefinition(); String beanName = buildDefaultBeanName(def); registerBean(def, beanName, parserContext); } return null; }
From source file:com.googlecode.icegem.cacheutils.common.PeerCacheService.java
/** * @param classLoader/*from w w w. ja va 2 s .c o m*/ * @throws Exception */ private void registerClasses(ClassLoader classLoader) throws Exception { List<Class<?>> classesFromPackages = new ArrayList<Class<?>>(); for (String pack : scanPackages) { log.info("Scan package " + pack + " for classes marked by @AutoSerializable"); ClassPathScanningCandidateComponentProvider ppp = new ClassPathScanningCandidateComponentProvider( false); ppp.addIncludeFilter(new AnnotationTypeFilter(AutoSerializable.class)); Set<BeanDefinition> candidateComponents = ppp.findCandidateComponents(pack); for (BeanDefinition beanDefinition : candidateComponents) { String className = beanDefinition.getBeanClassName(); final Class<?> clazz = Class.forName(className); classesFromPackages.add(clazz); } } try { HierarchyRegistry.registerAll(classLoader, classesFromPackages); } catch (InvalidClassException e) { final String msg = "Some class from list " + classesFromPackages + " is nor serializable. Cause: " + e.getMessage(); log.error(msg); throw new RuntimeException(msg, e); } catch (CannotCompileException e) { final String msg = "Can't compile DataSerializer classes for some classes from list " + classesFromPackages + ". Cause: " + e.getMessage(); log.error(msg); throw new RuntimeException(msg, e); } }
From source file:com.tacitknowledge.flip.spring.config.InterceptHandlerParserTest.java
@Test public void testCreateFlipHandlerAspect() { assertTrue(context.containsBeanDefinition(FlipSpringAspect.ASPECT_BEAN_NAME)); BeanDefinition flipHandlerAspectBeanDefinition = context .getBeanDefinition(FlipSpringAspect.ASPECT_BEAN_NAME); MutablePropertyValues properties = flipHandlerAspectBeanDefinition.getPropertyValues(); assertEquals(FlipSpringAspect.class.getName(), flipHandlerAspectBeanDefinition.getBeanClassName()); FlipSpringAspect aspect = context.getBean(FlipSpringAspect.ASPECT_BEAN_NAME, FlipSpringAspect.class); assertNotNull(aspect.getFeatureService()); assertNotNull(aspect.getDefaultValue()); assertEquals("test", aspect.getDefaultValue()); }
From source file:com.longio.spring.LioBootstrap.java
private void registerLioDefinition(ConfigurableListableBeanFactory beanFactory, BeanDefinition beanDefinition) { final String LioClassName = beanDefinition.getBeanClassName(); MutablePropertyValues propertyValues = beanDefinition.getPropertyValues(); /*/* w w w . j av a 2 s. com*/ * ?? MongoFactoryBean ?? */ propertyValues.addPropertyValue("objectType", LioClassName); ScannedGenericBeanDefinition scannedBeanDefinition = (ScannedGenericBeanDefinition) beanDefinition; scannedBeanDefinition.setPropertyValues(propertyValues); scannedBeanDefinition.setBeanClass(LioFactoryBean.class); scannedBeanDefinition.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE); DefaultListableBeanFactory defaultBeanFactory = (DefaultListableBeanFactory) beanFactory; defaultBeanFactory.registerBeanDefinition(LioClassName, beanDefinition); }
From source file:org.owasp.webgoat.plugins.PluginEndpointPublisher.java
private void publishEndpoint(Class<? extends MvcEndpoint> e) { try {//from w w w. ja v a2 s . c om 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:com.sourceallies.beanoh.BeanohTestCase.java
private void collectComponentsInClasspath(String basePackage, final Set<String> scannedComponents, ClassPathScanningCandidateComponentProvider scanner) { for (BeanDefinition beanDefinition : scanner.findCandidateComponents(basePackage)) { scannedComponents.add(beanDefinition.getBeanClassName()); }//w w w . jav a 2s. c o m }
From source file:com.joyveb.dbpimpl.cass.prepare.config.java.AbstractCassandraConfiguration.java
/** * Scans the mapping base package for classes annotated with {@link Table}. * /*from w w w. j a va 2 s .c o m*/ * @see #getMappingBasePackage() * @return * @throws ClassNotFoundException */ protected Set<Class<?>> getInitialEntitySet() { String basePackage = getMappingBasePackage(); Set<Class<?>> initialEntitySet = new HashSet<Class<?>>(); if (StringUtils.hasText(basePackage)) { ClassPathScanningCandidateComponentProvider componentProvider = new ClassPathScanningCandidateComponentProvider( false); componentProvider.addIncludeFilter(new AnnotationTypeFilter(Table.class)); componentProvider.addIncludeFilter(new AnnotationTypeFilter(Persistent.class)); for (BeanDefinition candidate : componentProvider.findCandidateComponents(basePackage)) { initialEntitySet.add(loadClass(candidate.getBeanClassName())); } } return initialEntitySet; }
From source file:com.longio.spring.LioBootstrap.java
private void doScanAndRegist(ConfigurableListableBeanFactory beanFactory) { LioScanningCandidateComponentProvider provider = new LioScanningCandidateComponentProvider(); provider.addIncludeFilter(new AnnotationTypeFilter(Lservice.class)); provider.addIncludeFilter(new AnnotationTypeFilter(LsFilter.class)); Set<String> LioClassNames = new HashSet<String>(); for (String pkg : basePackages) { Set<BeanDefinition> dfs = provider.findCandidateComponents(pkg); for (BeanDefinition beanDefinition : dfs) { String LioClassName = beanDefinition.getBeanClassName(); if (LioClassNames.contains(LioClassName)) { continue; }//from ww w . j a va 2 s . c om LioClassNames.add(LioClassName); registerLioDefinition(beanFactory, beanDefinition); } } }
From source file:com.googlecode.jsonrpc4j.spring.AutoJsonRpcServiceExporter.java
private Class<?>[] getBeanInterfaces(BeanDefinition serviceBeanDefinition, ClassLoader beanClassLoader) { String beanClassName = serviceBeanDefinition.getBeanClassName(); try {/* w w w. j av a2s .c o m*/ Class<?> beanClass = forName(beanClassName, beanClassLoader); return getAllInterfacesForClass(beanClass, beanClassLoader); } catch (ClassNotFoundException e) { throw new RuntimeException(format("Cannot find bean class '%s'.", beanClassName), e); } catch (LinkageError e) { throw new RuntimeException(format("Cannot find bean class '%s'.", beanClassName), e); } }