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

Remove @Inherited from @Primary [SPR-14780] #19346

Closed
spring-projects-issues opened this issue Oct 6, 2016 · 1 comment
Closed

Remove @Inherited from @Primary [SPR-14780] #19346

spring-projects-issues opened this issue Oct 6, 2016 · 1 comment

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Oct 6, 2016

Christopher Smith opened SPR-14780 and commented

This is a request for a breaking change in the API for Spring 5.

The @Primary annotation, which can be applied to interfaces, is currently marked as @Inherited. There are some cases in which factory-generated implementations of both a superinterface and subinterface are needed in the context, and @Primary cannot be used to indicate that the superinterface should be used non-invasively because it will be inherited by the subinterface.

As one concrete example of this in action, consider a UserRepository that is intended to be the backing store for a Spring Security UserDetailsService and also exported by Spring Data REST. The only mechanism for applying granular security to Spring Data REST is method-level security, but this breaks the repository for use in other areas of the application that aren't operating under the same security context.

The only manageable approach is to create a RestUserRepository extends UserRepository and apply the security annotations there. However, it is now unwieldy to inject a UserRepository into other consumers, as @Primary is unavailable. The only option is to add a qualifier to every other use of the dependency in the application.

Primary beans are an atypical case, and I believe that it is reasonable to expect that in the case where a user wants to apply @Primary to a subtype, the user is aware of that characteristic and can apply the annotation explicitly instead of inheriting it.


Affects: 4.3.3

0 votes, 5 watchers

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Oct 6, 2016

Juergen Hoeller commented

Agreed from my side. @Lazy isn't inherited either, so I don't see why @Primary needs to be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants