org.springframework.stereotype.Component Java Examples

The following examples show how to use org.springframework.stereotype.Component. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ClassPathScanningCandidateComponentProviderTests.java    From spring-analysis-note with MIT License 7 votes vote down vote up
@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(3, candidates.size());
	assertTrue(containsBeanClass(candidates, NamedComponent.class));
	assertTrue(containsBeanClass(candidates, ServiceInvocationCounter.class));
	assertTrue(containsBeanClass(candidates, BarComponent.class));
	assertFalse(containsBeanClass(candidates, FooServiceImpl.class));
	assertFalse(containsBeanClass(candidates, StubFooDao.class));
	assertFalse(containsBeanClass(candidates, NamedStubDao.class));
}
 
Example #2
Source File: NexusArtifactExtractor.java    From echo with Apache License 2.0 6 votes vote down vote up
@Override
public List<Artifact> getArtifacts(String source, Map payloadMap) {
  NexusPayload payload = mapper.convertValue(payloadMap, NexusPayload.class);
  if (payload.getComponent() == null) {
    return Collections.emptyList();
  } else {
    Component component = payload.getComponent();
    return Collections.singletonList(
        Artifact.builder()
            .type("maven/file")
            .name(component.getGroup() + ":" + component.getName())
            .reference(
                component.getGroup() + ":" + component.getName() + ":" + component.getVersion())
            .version(component.getVersion())
            .provenance(payload.getRepositoryName())
            .build());
  }
}
 
Example #3
Source File: ConfigurationManagerImpl.java    From zstack with Apache License 2.0 6 votes vote down vote up
private void generateApiMessageGroovyClass(StringBuilder sb, List<String> basePkgs) {
    ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(true);
    scanner.addIncludeFilter(new AssignableTypeFilter(APIMessage.class));
    scanner.addIncludeFilter(new AssignableTypeFilter(APIReply.class));
    scanner.addIncludeFilter(new AssignableTypeFilter(APIEvent.class));
    scanner.addExcludeFilter(new AnnotationTypeFilter(Controller.class));
    scanner.addExcludeFilter(new AnnotationTypeFilter(Component.class));
    for (String pkg : basePkgs) {
        for (BeanDefinition bd : scanner.findCandidateComponents(pkg)) {
            try {
                Class<?> clazz = Class.forName(bd.getBeanClassName());
                //classToApiMessageGroovyClass(sb, clazz);
                classToApiMessageGroovyInformation(sb, clazz);
            } catch (ClassNotFoundException e) {
                logger.warn(String.format("Unable to generate groovy class for %s", bd.getBeanClassName()), e);
            }
        }
    }
}
 
Example #4
Source File: ClassPathScanningCandidateComponentProviderTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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(3, candidates.size());
	assertTrue(containsBeanClass(candidates, NamedComponent.class));
	assertTrue(containsBeanClass(candidates, ServiceInvocationCounter.class));
	assertTrue(containsBeanClass(candidates, BarComponent.class));
	assertFalse(containsBeanClass(candidates, FooServiceImpl.class));
	assertFalse(containsBeanClass(candidates, StubFooDao.class));
	assertFalse(containsBeanClass(candidates, NamedStubDao.class));
}
 
Example #5
Source File: GroovyScriptFactoryTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
// Test for SPR-6268
public void testRefreshableFromTagProxyTargetClass() throws Exception {
	ApplicationContext ctx = new ClassPathXmlApplicationContext("groovy-with-xsd-proxy-target-class.xml",
			getClass());
	assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("refreshableMessenger"));

	Messenger messenger = (Messenger) ctx.getBean("refreshableMessenger");

	assertTrue(AopUtils.isAopProxy(messenger));
	assertTrue(messenger instanceof Refreshable);
	assertEquals("Hello World!", messenger.getMessage());

	assertTrue(ctx.getBeansOfType(ConcreteMessenger.class).values().contains(messenger));

	// Check that AnnotationUtils works with concrete proxied script classes
	assertNotNull(AnnotationUtils.findAnnotation(messenger.getClass(), Component.class));
}
 
Example #6
Source File: AnnotationMetadataTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
private void doTestMetadataForAnnotationClass(AnnotationMetadata metadata) {
	assertThat(metadata.getClassName(), is(Component.class.getName()));
	assertThat(metadata.isInterface(), is(true));
	assertThat(metadata.isAnnotation(), is(true));
	assertThat(metadata.isAbstract(), is(true));
	assertThat(metadata.isConcrete(), is(false));
	assertThat(metadata.hasSuperClass(), is(false));
	assertThat(metadata.getSuperClassName(), nullValue());
	assertThat(metadata.getInterfaceNames().length, is(1));
	assertThat(metadata.getInterfaceNames()[0], is(Annotation.class.getName()));
	assertThat(metadata.isAnnotated(Documented.class.getName()), is(false));
	assertThat(metadata.isAnnotated(Scope.class.getName()), is(false));
	assertThat(metadata.isAnnotated(SpecialAttr.class.getName()), is(false));
	assertThat(metadata.hasAnnotation(Documented.class.getName()), is(true));
	assertThat(metadata.hasAnnotation(Scope.class.getName()), is(false));
	assertThat(metadata.hasAnnotation(SpecialAttr.class.getName()), is(false));
	assertThat(metadata.getAnnotationTypes().size(), is(3));
}
 
Example #7
Source File: ClassReloaderImpl.java    From tephra with MIT License 6 votes vote down vote up
private String getBeanName(Class<?> clazz) {
    Component component = clazz.getAnnotation(Component.class);
    if (component != null)
        return component.value();

    Repository repository = clazz.getAnnotation(Repository.class);
    if (repository != null)
        return repository.value();

    Service service = clazz.getAnnotation(Service.class);
    if (service != null)
        return service.value();

    Controller controller = clazz.getAnnotation(Controller.class);
    if (controller != null)
        return controller.value();

    return null;
}
 
Example #8
Source File: AnnotationUtilsTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void synthesizeAnnotationFromAnnotationAttributesWithoutAttributeAliases() throws Exception {
	// 1) Get an annotation
	Component component = WebController.class.getAnnotation(Component.class);
	assertNotNull(component);

	// 2) Convert the annotation into AnnotationAttributes
	AnnotationAttributes attributes = getAnnotationAttributes(WebController.class, component);
	assertNotNull(attributes);

	// 3) Synthesize the AnnotationAttributes back into an annotation
	Component synthesizedComponent = synthesizeAnnotation(attributes, Component.class, WebController.class);
	assertNotNull(synthesizedComponent);

	// 4) Verify that the original and synthesized annotations are equivalent
	assertNotSame(component, synthesizedComponent);
	assertEquals(component, synthesizedComponent);
	assertEquals("value from component: ", "webController", component.value());
	assertEquals("value from synthesized component: ", "webController", synthesizedComponent.value());
}
 
Example #9
Source File: MetaAnnotationUtilsTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
private void assertAtComponentOnComposedAnnotationForMultipleCandidateTypes(Class<?> startClass,
		Class<?> rootDeclaringClass, Class<?> declaringClass, String name,
		Class<? extends Annotation> composedAnnotationType) {

	Class<Component> annotationType = Component.class;
	UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(
			startClass, Service.class, annotationType, Order.class, Transactional.class);

	assertNotNull("UntypedAnnotationDescriptor should not be null", descriptor);
	assertEquals("rootDeclaringClass", rootDeclaringClass, descriptor.getRootDeclaringClass());
	assertEquals("declaringClass", declaringClass, descriptor.getDeclaringClass());
	assertEquals("annotationType", annotationType, descriptor.getAnnotationType());
	assertEquals("component name", name, ((Component) descriptor.getAnnotation()).value());
	assertNotNull("composedAnnotation should not be null", descriptor.getComposedAnnotation());
	assertEquals("composedAnnotationType", composedAnnotationType, descriptor.getComposedAnnotationType());
}
 
Example #10
Source File: AnnotationUtilsTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void synthesizeAnnotationFromAnnotationAttributesWithoutAttributeAliases() throws Exception {
	// 1) Get an annotation
	Component component = WebController.class.getAnnotation(Component.class);
	assertNotNull(component);

	// 2) Convert the annotation into AnnotationAttributes
	AnnotationAttributes attributes = getAnnotationAttributes(WebController.class, component);
	assertNotNull(attributes);

	// 3) Synthesize the AnnotationAttributes back into an annotation
	Component synthesizedComponent = synthesizeAnnotation(attributes, Component.class, WebController.class);
	assertNotNull(synthesizedComponent);

	// 4) Verify that the original and synthesized annotations are equivalent
	assertNotSame(component, synthesizedComponent);
	assertEquals(component, synthesizedComponent);
	assertEquals("value from component: ", "webController", component.value());
	assertEquals("value from synthesized component: ", "webController", synthesizedComponent.value());
}
 
Example #11
Source File: SpringApplicationParser.java    From typescript-generator with MIT License 6 votes vote down vote up
public List<Class<?>> findRestControllers() {
    try (ConfigurableApplicationContext context = createApplicationContext()) {
        load(context, getAllSources().toArray());
        withSystemProperty("server.port", "0", () -> {
            context.refresh();
        });
        final List<Class<?>> classes = Stream.of(context.getBeanDefinitionNames())
            .map(beanName -> context.getBeanFactory().getBeanDefinition(beanName).getBeanClassName())
            .filter(Objects::nonNull)
            .filter(className -> isClassNameExcluded == null || !isClassNameExcluded.test(className))
            .map(className -> {
                try {
                    return classLoader.loadClass(className);
                } catch (ClassNotFoundException e) {
                    throw new RuntimeException(e);
                }
            })
            .filter(instance -> AnnotationUtils.findAnnotation(instance, Component.class) != null)
            .collect(Collectors.toList());
        return classes;
    }
}
 
Example #12
Source File: AnnotationMetadataTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
private void doTestMetadataForAnnotationClass(AnnotationMetadata metadata) {
	assertThat(metadata.getClassName(), is(Component.class.getName()));
	assertThat(metadata.isInterface(), is(true));
	assertThat(metadata.isAnnotation(), is(true));
	assertThat(metadata.isAbstract(), is(true));
	assertThat(metadata.isConcrete(), is(false));
	assertThat(metadata.hasSuperClass(), is(false));
	assertThat(metadata.getSuperClassName(), nullValue());
	assertThat(metadata.getInterfaceNames().length, is(1));
	assertThat(metadata.getInterfaceNames()[0], is(Annotation.class.getName()));
	assertThat(metadata.isAnnotated(Documented.class.getName()), is(false));
	assertThat(metadata.isAnnotated(Scope.class.getName()), is(false));
	assertThat(metadata.isAnnotated(SpecialAttr.class.getName()), is(false));
	assertThat(metadata.hasAnnotation(Documented.class.getName()), is(false));
	assertThat(metadata.hasAnnotation(Scope.class.getName()), is(false));
	assertThat(metadata.hasAnnotation(SpecialAttr.class.getName()), is(false));
	assertThat(metadata.getAnnotationTypes().size(), is(1));
}
 
Example #13
Source File: AnnotationMetadataTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
private void doTestSubClassAnnotationInfo(AnnotationMetadata metadata) {
	assertThat(metadata.getClassName(), is(AnnotatedComponentSubClass.class.getName()));
	assertThat(metadata.isInterface(), is(false));
	assertThat(metadata.isAnnotation(), is(false));
	assertThat(metadata.isAbstract(), is(false));
	assertThat(metadata.isConcrete(), is(true));
	assertThat(metadata.hasSuperClass(), is(true));
	assertThat(metadata.getSuperClassName(), is(AnnotatedComponent.class.getName()));
	assertThat(metadata.getInterfaceNames().length, is(0));
	assertThat(metadata.isAnnotated(Component.class.getName()), is(false));
	assertThat(metadata.isAnnotated(Scope.class.getName()), is(false));
	assertThat(metadata.isAnnotated(SpecialAttr.class.getName()), is(false));
	assertThat(metadata.hasAnnotation(Component.class.getName()), is(false));
	assertThat(metadata.hasAnnotation(Scope.class.getName()), is(false));
	assertThat(metadata.hasAnnotation(SpecialAttr.class.getName()), is(false));
	assertThat(metadata.getAnnotationTypes().size(), is(0));
	assertThat(metadata.getAnnotationAttributes(Component.class.getName()), nullValue());
	assertThat(metadata.getAnnotatedMethods(DirectAnnotation.class.getName()).size(), equalTo(0));
	assertThat(metadata.isAnnotated(IsAnnotatedAnnotation.class.getName()), equalTo(false));
	assertThat(metadata.getAllAnnotationAttributes(DirectAnnotation.class.getName()), nullValue());
}
 
Example #14
Source File: AnnotationMetadataTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
private void doTestSubClassAnnotationInfo(AnnotationMetadata metadata) {
	assertThat(metadata.getClassName(), is(AnnotatedComponentSubClass.class.getName()));
	assertThat(metadata.isInterface(), is(false));
	assertThat(metadata.isAnnotation(), is(false));
	assertThat(metadata.isAbstract(), is(false));
	assertThat(metadata.isConcrete(), is(true));
	assertThat(metadata.hasSuperClass(), is(true));
	assertThat(metadata.getSuperClassName(), is(AnnotatedComponent.class.getName()));
	assertThat(metadata.getInterfaceNames().length, is(0));
	assertThat(metadata.isAnnotated(Component.class.getName()), is(false));
	assertThat(metadata.isAnnotated(Scope.class.getName()), is(false));
	assertThat(metadata.isAnnotated(SpecialAttr.class.getName()), is(false));
	assertThat(metadata.hasAnnotation(Component.class.getName()), is(false));
	assertThat(metadata.hasAnnotation(Scope.class.getName()), is(false));
	assertThat(metadata.hasAnnotation(SpecialAttr.class.getName()), is(false));
	assertThat(metadata.getAnnotationTypes().size(), is(0));
	assertThat(metadata.getAnnotationAttributes(Component.class.getName()), nullValue());
	assertThat(metadata.getAnnotatedMethods(DirectAnnotation.class.getName()).size(), equalTo(0));
	assertThat(metadata.isAnnotated(IsAnnotatedAnnotation.class.getName()), equalTo(false));
	assertThat(metadata.getAllAnnotationAttributes(DirectAnnotation.class.getName()), nullValue());
}
 
Example #15
Source File: MetaAnnotationUtilsTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private void assertAtComponentOnComposedAnnotation(Class<?> startClass, Class<?> rootDeclaringClass,
		Class<?> declaringClass, String name, Class<? extends Annotation> composedAnnotationType) {

	AnnotationDescriptor<Component> descriptor = findAnnotationDescriptor(startClass, Component.class);
	assertNotNull("AnnotationDescriptor should not be null", descriptor);
	assertEquals("rootDeclaringClass", rootDeclaringClass, descriptor.getRootDeclaringClass());
	assertEquals("declaringClass", declaringClass, descriptor.getDeclaringClass());
	assertEquals("annotationType", Component.class, descriptor.getAnnotationType());
	assertEquals("component name", name, descriptor.getAnnotation().value());
	assertNotNull("composedAnnotation should not be null", descriptor.getComposedAnnotation());
	assertEquals("composedAnnotationType", composedAnnotationType, descriptor.getComposedAnnotationType());
}
 
Example #16
Source File: MetaAnnotationUtilsTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
private void assertAtComponentOnComposedAnnotation(Class<?> startClass, Class<?> rootDeclaringClass,
		Class<?> declaringClass, String name, Class<? extends Annotation> composedAnnotationType) {

	AnnotationDescriptor<Component> descriptor = findAnnotationDescriptor(startClass, Component.class);
	assertNotNull("AnnotationDescriptor should not be null", descriptor);
	assertEquals("rootDeclaringClass", rootDeclaringClass, descriptor.getRootDeclaringClass());
	assertEquals("declaringClass", declaringClass, descriptor.getDeclaringClass());
	assertEquals("annotationType", Component.class, descriptor.getAnnotationType());
	assertEquals("component name", name, descriptor.getAnnotation().value());
	assertNotNull("composedAnnotation should not be null", descriptor.getComposedAnnotation());
	assertEquals("composedAnnotationType", composedAnnotationType, descriptor.getComposedAnnotationType());
}
 
Example #17
Source File: MetaAnnotationUtilsTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * @since 4.0.3
 */
@Test
@SuppressWarnings("unchecked")
public void findAnnotationDescriptorForTypesOnAnnotatedClassWithMissingTargetMetaAnnotation() {
	// InheritedAnnotationClass is NOT annotated or meta-annotated with @Component,
	// @Service, or @Order, but it is annotated with @Transactional.
	UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(
			InheritedAnnotationClass.class, Service.class, Component.class, Order.class);
	assertNull("Should not find @Component on InheritedAnnotationClass", descriptor);
}
 
Example #18
Source File: CandidateComponentsIndexerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
private void testComponent(Class<?>... classes) {
	CandidateComponentsMetadata metadata = compile(classes);
	for (Class<?> c : classes) {
		assertThat(metadata, hasComponent(c, Component.class));
	}
	assertThat(metadata.getItems(), hasSize(classes.length));
}
 
Example #19
Source File: AnnotationUtilsTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void synthesizeAnnotationFromMapWithAttributeOfIncorrectType() throws Exception {
	Map<String, Object> map = Collections.singletonMap(VALUE, 42L);

	exception.expect(IllegalArgumentException.class);
	exception.expectMessage(startsWith("Attributes map"));
	exception.expectMessage(containsString("returned a value of type [java.lang.Long]"));
	exception.expectMessage(containsString("for attribute [value]"));
	exception.expectMessage(containsString("but a value of type [java.lang.String] is required"));
	exception.expectMessage(containsString("as defined by annotation type [" + Component.class.getName() + "]"));
	synthesizeAnnotation(map, Component.class, null);
}
 
Example #20
Source File: MetaAnnotationUtilsTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void findAnnotationDescriptorForClassWithMetaAnnotatedInterface() {
	Component rawAnnotation = AnnotationUtils.findAnnotation(ClassWithMetaAnnotatedInterface.class, Component.class);
	AnnotationDescriptor<Component> descriptor =
			findAnnotationDescriptor(ClassWithMetaAnnotatedInterface.class, Component.class);

	assertNotNull(descriptor);
	assertEquals(ClassWithMetaAnnotatedInterface.class, descriptor.getRootDeclaringClass());
	assertEquals(Meta1.class, descriptor.getDeclaringClass());
	assertEquals(rawAnnotation, descriptor.getAnnotation());
	assertEquals(Meta1.class, descriptor.getComposedAnnotation().annotationType());
}
 
Example #21
Source File: AnnotationMetadataTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void asmAnnotationMetadataForAnnotation() throws Exception {
	MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
	MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(Component.class.getName());
	AnnotationMetadata metadata = metadataReader.getAnnotationMetadata();
	doTestMetadataForAnnotationClass(metadata);
}
 
Example #22
Source File: MetaAnnotationUtilsTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void findAnnotationDescriptorForTypesForClassWithMetaAnnotatedInterface() {
	Component rawAnnotation = AnnotationUtils.findAnnotation(ClassWithMetaAnnotatedInterface.class, Component.class);

	UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(
			ClassWithMetaAnnotatedInterface.class, Service.class, Component.class, Order.class, Transactional.class);

	assertNotNull(descriptor);
	assertEquals(ClassWithMetaAnnotatedInterface.class, descriptor.getRootDeclaringClass());
	assertEquals(Meta1.class, descriptor.getDeclaringClass());
	assertEquals(rawAnnotation, descriptor.getAnnotation());
	assertEquals(Meta1.class, descriptor.getComposedAnnotation().annotationType());
}
 
Example #23
Source File: AnnotationTypeFilterTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testNonAnnotatedClassDoesntMatch() throws Exception {
	MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
	String classUnderTest = "org.springframework.core.type.AnnotationTypeFilterTests$SomeNonCandidateClass";
	MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(classUnderTest);

	AnnotationTypeFilter filter = new AnnotationTypeFilter(Component.class);
	assertFalse(filter.match(metadataReader, metadataReaderFactory));
	ClassloadingAssertions.assertClassNotLoaded(classUnderTest);
}
 
Example #24
Source File: CandidateComponentsIndexerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void embeddedCandidatesAreDetected()
		throws IOException, ClassNotFoundException {
	// Validate nested type structure
	String nestedType = "org.springframework.context.index.sample.SampleEmbedded.Another$AnotherPublicCandidate";
	Class<?> type = ClassUtils.forName(nestedType, getClass().getClassLoader());
	assertThat(type, sameInstance(SampleEmbedded.Another.AnotherPublicCandidate.class));

	CandidateComponentsMetadata metadata = compile(SampleEmbedded.class);
	assertThat(metadata, hasComponent(
			SampleEmbedded.PublicCandidate.class, Component.class));
	assertThat(metadata, hasComponent(nestedType, Component.class.getName()));
	assertThat(metadata.getItems(), hasSize(2));
}
 
Example #25
Source File: MergedAnnotationsTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void synthesizeFromMapWithoutAttributeAliases() throws Exception {
	Component component = WebController.class.getAnnotation(Component.class);
	assertThat(component).isNotNull();
	Map<String, Object> map = Collections.singletonMap("value", "webController");
	MergedAnnotation<Component> annotation = MergedAnnotation.of(Component.class,
			map);
	Component synthesizedComponent = annotation.synthesize();
	assertThat(synthesizedComponent).isInstanceOf(SynthesizedAnnotation.class);
	assertThat(synthesizedComponent.value()).isEqualTo("webController");
}
 
Example #26
Source File: MergedAnnotationsTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void synthesizeWithoutAttributeAliases() throws Exception {
	Component component = WebController.class.getAnnotation(Component.class);
	assertThat(component).isNotNull();
	Component synthesizedComponent = MergedAnnotation.from(component).synthesize();
	assertThat(synthesizedComponent).isNotNull();
	assertThat(synthesizedComponent).isEqualTo(component);
	assertThat(synthesizedComponent.value()).isEqualTo("webController");
}
 
Example #27
Source File: MergedAnnotationsTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void getDirectFromClassWithMetaCycleAnnotatedClassWithMissingTargetMetaAnnotation() {
	MergedAnnotation<?> annotation = MergedAnnotations.from(
			MetaCycleAnnotatedClass.class, SearchStrategy.EXHAUSTIVE).get(
					Component.class);
	assertThat(annotation.isPresent()).isFalse();
}
 
Example #28
Source File: AnnotationUtilsTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void synthesizeAnnotationFromMapWithoutAttributeAliases() throws Exception {
	Component component = WebController.class.getAnnotation(Component.class);
	assertNotNull(component);

	Map<String, Object> map = Collections.singletonMap(VALUE, "webController");
	Component synthesizedComponent = synthesizeAnnotation(map, Component.class, WebController.class);
	assertNotNull(synthesizedComponent);

	assertNotSame(component, synthesizedComponent);
	assertEquals("value from component: ", "webController", component.value());
	assertEquals("value from synthesized component: ", "webController", synthesizedComponent.value());
}
 
Example #29
Source File: ModuleClassLoader.java    From TrackRay with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 方法描述 判断class对象是否带有spring的注解
 * @method isSpringBeanClass
 * @param cla jar中的每一个class
 * @return true 是spring bean   false 不是spring bean
 */
public boolean isSpringBeanClass(Class<?> cla){
    if(cla==null){
        return false;
    }
    //是否是接口
    if(cla.isInterface()){
        return false;
    }

    //是否是抽象类
    if( Modifier.isAbstract(cla.getModifiers())){
        return false;
    }

    if(cla.getAnnotation(Component.class)!=null){
        return true;
    }
    if(cla.getAnnotation(Repository.class)!=null){
        return true;
    }
    if(cla.getAnnotation(Service.class)!=null){
        return true;
    }

    return false;
}
 
Example #30
Source File: ClassPathScanningCandidateComponentProviderTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testWithMultipleMatchingFilters() {
	ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
	provider.addIncludeFilter(new AnnotationTypeFilter(Component.class));
	provider.addIncludeFilter(new AssignableTypeFilter(FooServiceImpl.class));
	Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
	assertEquals(7, candidates.size());
	assertTrue(containsBeanClass(candidates, NamedComponent.class));
	assertTrue(containsBeanClass(candidates, ServiceInvocationCounter.class));
	assertTrue(containsBeanClass(candidates, FooServiceImpl.class));
	assertTrue(containsBeanClass(candidates, BarComponent.class));
}