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

Define alias for component-scanned bean via annotation [SPR-6736] #11402

Closed
spring-projects-issues opened this issue Jan 20, 2010 · 11 comments
Closed
Labels
has: votes-jira Issues migrated from JIRA with more than 10 votes at the time of import in: core Issues in core modules (aop, beans, core, context, expression) status: declined A suggestion or change that we don't feel we should currently apply

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Jan 20, 2010

adrian opened SPR-6736 and commented

I'm using Struts 1 with the Spring DelegatingTilesRequestProcessor plugin.
I define my actions as spring beans and would like to use @Component annotation and no XML configuration.

My problem is that an action path must correspond to the same Spring bean id.

And I can have the same spring bean used for multiple actions.

i.e /charge/view and /charge/save should map to the same bean.

I cannot do it with @Component annotation alone, and would need a @Alias or @Role annotation.

For instance something like :

@Component("/charge/view")
@Roles({`@Role`("/charge/remove"),
    @Role("/charge/edit"),
    @Role("/charge/save")})
public class EditChargeClienteleAction extends MappingDispatchAction {

Affects: 3.0 GA

Reference URL: http://forum.springsource.org/showthread.php?t=83133

16 votes, 12 watchers

@spring-projects-issues
Copy link
Collaborator Author

Gergő Takács commented

It would be great for me too

@spring-projects-issues
Copy link
Collaborator Author

Stevo Slavić commented

This is already supported outside of XML, albeit not with @Role/@Roles but with Spring Java @Configuration and bean aliasing (see here for more).

@spring-projects-issues
Copy link
Collaborator Author

Hendy Irawan commented

+1 for this. outside Spring MVC bean aliasing is also useful.

@Configuration is a workaround, the same aliasing mechanism should be supported by @Component/@Service etc. (by accepting String[] instead of just String, or adding 'aliases')

@spring-projects-issues
Copy link
Collaborator Author

M. Justin commented

Agreed that @Component/@Service, etc. beans should support defining the alias name without using @Configuration.

@spring-projects-issues spring-projects-issues added status: waiting-for-triage An issue we've not yet triaged or decided on type: enhancement A general enhancement in: core Issues in core modules (aop, beans, core, context, expression) has: votes-jira Issues migrated from JIRA with more than 10 votes at the time of import and removed type: enhancement A general enhancement labels Jan 11, 2019
@rstoyanchev rstoyanchev added status: bulk-closed An outdated, unresolved issue that's closed in bulk as part of a cleaning process and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jan 11, 2019
@spring-projects-issues
Copy link
Collaborator Author

Bulk closing outdated, unresolved issues. Please, reopen if still relevant.

@foal
Copy link

foal commented Jan 15, 2019

Still relevant

@rstoyanchev rstoyanchev reopened this Jan 21, 2019
@rstoyanchev rstoyanchev added status: waiting-for-triage An issue we've not yet triaged or decided on for: team-attention and removed status: bulk-closed An outdated, unresolved issue that's closed in bulk as part of a cleaning process labels Jan 21, 2019
@rstoyanchev rstoyanchev added status: bulk-closed An outdated, unresolved issue that's closed in bulk as part of a cleaning process and removed for: team-attention labels Jun 28, 2019
@itsLucario
Copy link

This issue is open from 2010. Spring must look into this feature request.

@mauromol
Copy link

I also think this is a missing feature in Spring annotations. Probably an alias property of @Component or an @Alias annotation could do the trick?

@snicoll snicoll removed the status: bulk-closed An outdated, unresolved issue that's closed in bulk as part of a cleaning process label Dec 28, 2021
@AdrianLopez1994
Copy link

Still relevant.

@fibsifan
Copy link

+1

@sbrannen sbrannen changed the title define a bean alias with annotations (similar to @Component but just defining an alias) [SPR-6736] Define alias for component-scanned bean via annotation [SPR-6736] Dec 19, 2022
@sbrannen sbrannen added the type: enhancement A general enhancement label Dec 19, 2022
@snicoll
Copy link
Member

snicoll commented Oct 3, 2023

Thanks for the suggestion but, after a careful consideration, we're going to decline this. @Component is a simple way of registering new beans in the bean factory that is decoupled from BeanDefinition. As such, adding an alias to it does not really make sense.

If you need to register a bean with multiple aliases, please use the @Configuration model with @Bean that provides a way for you to provide several bean names.

@snicoll snicoll closed this as not planned Won't fix, can't repro, duplicate, stale Oct 3, 2023
@snicoll snicoll added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged or decided on type: enhancement A general enhancement labels Oct 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has: votes-jira Issues migrated from JIRA with more than 10 votes at the time of import in: core Issues in core modules (aop, beans, core, context, expression) status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

No branches or pull requests

9 participants