Search in sources :

Example 11 with Component

use of org.springframework.stereotype.Component in project spring-framework by spring-projects.

the class AnnotationUtilsTests method findClassAnnotationOnMetaCycleAnnotatedClassWithMissingTargetMetaAnnotation.

@Test
public void findClassAnnotationOnMetaCycleAnnotatedClassWithMissingTargetMetaAnnotation() {
    Component component = findAnnotation(MetaCycleAnnotatedClass.class, Component.class);
    assertNull("Should not find @Component on MetaCycleAnnotatedClass", component);
}
Also used : Component(org.springframework.stereotype.Component) Test(org.junit.Test)

Example 12 with Component

use of org.springframework.stereotype.Component in project spring-framework by spring-projects.

the class AnnotationUtilsTests method findClassAnnotationOnMetaMetaAnnotatedClass.

@Test
public void findClassAnnotationOnMetaMetaAnnotatedClass() {
    Component component = findAnnotation(MetaMetaAnnotatedClass.class, Component.class);
    assertNotNull("Should find meta-annotation on composed annotation on class", component);
    assertEquals("meta2", component.value());
}
Also used : Component(org.springframework.stereotype.Component) Test(org.junit.Test)

Example 13 with Component

use of org.springframework.stereotype.Component in project spring-framework by spring-projects.

the class AnnotationUtilsTests method synthesizeAnnotationFromAnnotationAttributesWithoutAttributeAliases.

@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());
}
Also used : Component(org.springframework.stereotype.Component) Test(org.junit.Test)

Example 14 with Component

use of org.springframework.stereotype.Component in project spring-framework by spring-projects.

the class AnnotationUtilsTests method findClassAnnotationFavorsMoreLocallyDeclaredComposedAnnotationsOverAnnotationsOnInterfaces.

/** @since 4.1.2 */
@Test
public void findClassAnnotationFavorsMoreLocallyDeclaredComposedAnnotationsOverAnnotationsOnInterfaces() {
    Component component = findAnnotation(ClassWithLocalMetaAnnotationAndMetaAnnotatedInterface.class, Component.class);
    assertNotNull(component);
    assertEquals("meta2", component.value());
}
Also used : Component(org.springframework.stereotype.Component) Test(org.junit.Test)

Example 15 with Component

use of org.springframework.stereotype.Component in project spring-framework by spring-projects.

the class ClassPathScanningCandidateComponentProvider method registerDefaultFilters.

/**
	 * Register the default filter for {@link Component @Component}.
	 * <p>This will implicitly register all annotations that have the
	 * {@link Component @Component} meta-annotation including the
	 * {@link Repository @Repository}, {@link Service @Service}, and
	 * {@link Controller @Controller} stereotype annotations.
	 * <p>Also supports Java EE 6's {@link javax.annotation.ManagedBean} and
	 * JSR-330's {@link javax.inject.Named} annotations, if available.
	 *
	 */
@SuppressWarnings("unchecked")
protected void registerDefaultFilters() {
    this.includeFilters.add(new AnnotationTypeFilter(Component.class));
    ClassLoader cl = ClassPathScanningCandidateComponentProvider.class.getClassLoader();
    try {
        this.includeFilters.add(new AnnotationTypeFilter(((Class<? extends Annotation>) ClassUtils.forName("javax.annotation.ManagedBean", cl)), false));
        logger.debug("JSR-250 'javax.annotation.ManagedBean' found and supported for component scanning");
    } catch (ClassNotFoundException ex) {
    // JSR-250 1.1 API (as included in Java EE 6) not available - simply skip.
    }
    try {
        this.includeFilters.add(new AnnotationTypeFilter(((Class<? extends Annotation>) ClassUtils.forName("javax.inject.Named", cl)), false));
        logger.debug("JSR-330 'javax.inject.Named' annotation found and supported for component scanning");
    } catch (ClassNotFoundException ex) {
    // JSR-330 API not available - simply skip.
    }
}
Also used : AnnotationTypeFilter(org.springframework.core.type.filter.AnnotationTypeFilter) Component(org.springframework.stereotype.Component)

Aggregations

Component (org.springframework.stereotype.Component)18 Test (org.junit.Test)14 UntypedAnnotationDescriptor (org.springframework.test.util.MetaAnnotationUtils.UntypedAnnotationDescriptor)3 Method (java.lang.reflect.Method)1 Binding (org.glassfish.jersey.internal.inject.Binding)1 Order (org.springframework.core.annotation.Order)1 AnnotationTypeFilter (org.springframework.core.type.filter.AnnotationTypeFilter)1 Service (org.springframework.stereotype.Service)1 Transactional (org.springframework.transaction.annotation.Transactional)1 WebApplicationContext (org.springframework.web.context.WebApplicationContext)1