Java Code Examples for org.springframework.stereotype.Service

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project Blitz, under directory /src/com/laxser/blitz/web/impl/module/.

Source file: ModulesBuilderImpl.java

  19 
vote

private void registerBeanDefinitions(XmlWebApplicationContext context,List<Class<?>> classes){
  DefaultListableBeanFactory bf=(DefaultListableBeanFactory)context.getBeanFactory();
  String[] definedClasses=new String[bf.getBeanDefinitionCount()];
  String[] definitionNames=bf.getBeanDefinitionNames();
  for (int i=0; i < definedClasses.length; i++) {
    String name=definitionNames[i];
    definedClasses[i]=bf.getBeanDefinition(name).getBeanClassName();
  }
  for (  Class<?> clazz : classes) {
    if (!isCandidate(clazz)) {
      continue;
    }
    String clazzName=clazz.getName();
    if (ArrayUtils.contains(definedClasses,clazzName)) {
      if (logger.isDebugEnabled()) {
        logger.debug("Ignores bean definition because it has been exist in context: " + clazz.getName());
      }
      continue;
    }
    String beanName=null;
    if (StringUtils.isEmpty(beanName) && clazz.isAnnotationPresent(Component.class)) {
      beanName=clazz.getAnnotation(Component.class).value();
    }
    if (StringUtils.isEmpty(beanName) && clazz.isAnnotationPresent(Resource.class)) {
      beanName=clazz.getAnnotation(Resource.class).name();
    }
    if (StringUtils.isEmpty(beanName) && clazz.isAnnotationPresent(Service.class)) {
      beanName=clazz.getAnnotation(Service.class).value();
    }
    if (StringUtils.isEmpty(beanName)) {
      beanName=AUTO_BEAN_NAME_PREFIX + clazz.getName();
    }
    bf.registerBeanDefinition(beanName,new AnnotatedGenericBeanDefinition(clazz));
  }
}
 

Example 2

From project spring-js, under directory /src/test/java/org/springframework/context/annotation/.

Source file: ClassPathScanningCandidateComponentProviderTests.java

  19 
vote

@Test public void testWithComponentAnnotationOnly(){
  ClassPathScanningCandidateComponentProvider provider=new ClassPathScanningCandidateComponentProvider(false);
  provider.addIncludeFilter(new AnnotationTypeFilter(Component.class));
  provider.addExcludeFilter(new AnnotationTypeFilter(Repository.class));
  provider.addExcludeFilter(new AnnotationTypeFilter(Service.class));
  provider.addExcludeFilter(new AnnotationTypeFilter(Controller.class));
  Set<BeanDefinition> candidates=provider.findCandidateComponents(TEST_BASE_PACKAGE);
  assertEquals(2,candidates.size());
  assertTrue(containsBeanClass(candidates,NamedComponent.class));
  assertTrue(containsBeanClass(candidates,ServiceInvocationCounter.class));
  assertFalse(containsBeanClass(candidates,FooServiceImpl.class));
  assertFalse(containsBeanClass(candidates,StubFooDao.class));
  assertFalse(containsBeanClass(candidates,NamedStubDao.class));
}