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;
}
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());
}
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());
}
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()));
}
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());
}
Aggregations