use of org.springframework.stereotype.Component in project spring-framework by spring-projects.
the class AnnotationUtilsTests method findClassAnnotationOnAnnotatedClassWithMissingTargetMetaAnnotation.
@Test
public void findClassAnnotationOnAnnotatedClassWithMissingTargetMetaAnnotation() {
// TransactionalClass is NOT annotated or meta-annotated with @Component
Component component = findAnnotation(TransactionalClass.class, Component.class);
assertNull("Should not find @Component on TransactionalClass", component);
}
use of org.springframework.stereotype.Component in project spring-framework by spring-projects.
the class AnnotationUtilsTests method getAnnotationAttributesWithoutAttributeAliases.
@Test
public void getAnnotationAttributesWithoutAttributeAliases() {
Component component = WebController.class.getAnnotation(Component.class);
assertNotNull(component);
AnnotationAttributes attributes = (AnnotationAttributes) getAnnotationAttributes(component);
assertNotNull(attributes);
assertEquals("value attribute: ", "webController", attributes.getString(VALUE));
assertEquals(Component.class, attributes.annotationType());
}
use of org.springframework.stereotype.Component in project spring-framework by spring-projects.
the class MetaAnnotationUtilsTests method assertAtComponentOnComposedAnnotationForMultipleCandidateTypes.
@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());
}
use of org.springframework.stereotype.Component in project spring-framework by spring-projects.
the class SpringConfigurator method getEndpointInstance.
@SuppressWarnings("unchecked")
@Override
public <T> T getEndpointInstance(Class<T> endpointClass) throws InstantiationException {
WebApplicationContext wac = ContextLoader.getCurrentWebApplicationContext();
if (wac == null) {
String message = "Failed to find the root WebApplicationContext. Was ContextLoaderListener not used?";
logger.error(message);
throw new IllegalStateException(message);
}
String beanName = ClassUtils.getShortNameAsProperty(endpointClass);
if (wac.containsBean(beanName)) {
T endpoint = wac.getBean(beanName, endpointClass);
if (logger.isTraceEnabled()) {
logger.trace("Using @ServerEndpoint singleton " + endpoint);
}
return endpoint;
}
Component ann = AnnotationUtils.findAnnotation(endpointClass, Component.class);
if (ann != null && wac.containsBean(ann.value())) {
T endpoint = wac.getBean(ann.value(), endpointClass);
if (logger.isTraceEnabled()) {
logger.trace("Using @ServerEndpoint singleton " + endpoint);
}
return endpoint;
}
beanName = getBeanNameByType(wac, endpointClass);
if (beanName != null) {
return (T) wac.getBean(beanName);
}
if (logger.isTraceEnabled()) {
logger.trace("Creating new @ServerEndpoint instance of type " + endpointClass);
}
return wac.getAutowireCapableBeanFactory().createBean(endpointClass);
}
use of org.springframework.stereotype.Component in project spring-framework by spring-projects.
the class AnnotationUtilsTests method synthesizeAnnotationFromMapWithoutAttributeAliases.
@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());
}
Aggregations