Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Annotations like @Service should add @AliasFor for @Component [SPR-16066] #20615

Closed
spring-issuemaster opened this issue Oct 13, 2017 · 3 comments

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

commented Oct 13, 2017

Yanming Zhou opened SPR-16066 and commented

@Service is a specialization of @Component, like @GetMapping is a specialization of @RequestMapping, @Service should add @AliasFor like @GetMapping

@Component
public @interface Service
{
  @AliasFor(annotation=Component.class)
  String value() default "";
}

We can get metadata from annotation via unified code

Component component = AnnotatedElementUtils.getMergedAnnotation(clazz, @Component.class);
String beanName = component.value();

Referenced from: commits 43b5e21, 625737f

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Oct 13, 2017

Sam Brannen commented

Juergen Hoeller, any reason not to apply the same change to annotations such as @Configuration, @RestController, @ControllerAdvice, @RestControllerAdvice, etc.?

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Oct 13, 2017

Juergen Hoeller commented

Good point :-) I've added similar declarations to @Configuration and @RestController (with the alias pointing to @Controller in the latter case). The controller advices don't have a value attribute with bean name semantics, so don't seem applicable here.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Oct 13, 2017

Sam Brannen commented

I've added similar declarations to @Configuration and @RestController (with the alias pointing to @Controller in the latter case).

Cool. Thanks!

The controller advices don't have a value attribute with bean name semantics, so don't seem applicable here.

MMmmmmmm... indeed. I just listed off stereotypes without actually checking the source code. ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.