Search in sources :

Example 1 with Component

use of org.springframework.stereotype.Component in project jersey by jersey.

the class SpringComponentProvider method bind.

// detect JAX-RS classes that are also Spring @Components.
// register these with HK2 ServiceLocator to manage their lifecycle using Spring.
@Override
public boolean bind(Class<?> component, Set<Class<?>> providerContracts) {
    if (ctx == null) {
        return false;
    }
    if (AnnotationUtils.findAnnotation(component, Component.class) != null) {
        String[] beanNames = ctx.getBeanNamesForType(component);
        if (beanNames == null || beanNames.length != 1) {
            LOGGER.severe(LocalizationMessages.NONE_OR_MULTIPLE_BEANS_AVAILABLE(component));
            return false;
        }
        String beanName = beanNames[0];
        Binding binding = Bindings.supplier(new SpringManagedBeanFactory(ctx, injectionManager, beanName)).to(component).to(providerContracts);
        injectionManager.register(binding);
        LOGGER.config(LocalizationMessages.BEAN_REGISTERED(beanNames[0]));
        return true;
    }
    return false;
}
Also used : Binding(org.glassfish.jersey.internal.inject.Binding) Component(org.springframework.stereotype.Component)

Example 2 with Component

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

the class AnnotationUtilsTests method synthesizeAnnotationWithoutAttributeAliases.

@Test
public void synthesizeAnnotationWithoutAttributeAliases() throws Exception {
    Component component = WebController.class.getAnnotation(Component.class);
    assertNotNull(component);
    Component synthesizedComponent = synthesizeAnnotation(component);
    assertNotNull(synthesizedComponent);
    assertSame(component, synthesizedComponent);
    assertEquals("value attribute: ", "webController", synthesizedComponent.value());
}
Also used : Component(org.springframework.stereotype.Component) Test(org.junit.Test)

Example 3 with Component

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

the class AnnotationUtilsTests method findClassAnnotationFavorsMoreLocallyDeclaredComposedAnnotationsOverInheritedComposedAnnotations.

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

Example 4 with Component

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

the class AnnotationUtilsTests method getAttributeOverrideNameFromWrongTargetAnnotation.

@Test
public void getAttributeOverrideNameFromWrongTargetAnnotation() throws Exception {
    Method attribute = AliasedComposedContextConfig.class.getDeclaredMethod("xmlConfigFile");
    assertThat("xmlConfigFile is not an alias for @Component.", getAttributeOverrideName(attribute, Component.class), is(nullValue()));
}
Also used : Method(java.lang.reflect.Method) Component(org.springframework.stereotype.Component) Test(org.junit.Test)

Example 5 with Component

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

the class AnnotationUtilsTests method findClassAnnotationOnMetaMetaMetaAnnotatedClass.

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

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