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

Try using @Resource instead of @Autowire #7

Open
ddtxra opened this issue Oct 6, 2014 · 2 comments
Open

Try using @Resource instead of @Autowire #7

ddtxra opened this issue Oct 6, 2014 · 2 comments

Comments

@ddtxra
Copy link
Contributor

ddtxra commented Oct 6, 2014

Since we have 2 implementations of data source (user and core), @autowire does not know how to inject them. Apparently one can inject resources using its name with the @resource annotation. That may be the solution instead of using the DatasourceServiceLocator.

See:
http://stackoverflow.com/questions/4093504/resource-vs-autowired

Both @Autowired (or @Inject) and @resource work equally well. But there is a conceptual difference or a difference in the meaning

@resource means get me a known resource by name. The name is extracted from the name of the annotated setter or field, or it is taken from the name-Parameter.
@Inject or @Autowired try to wire in a suitable other component by type.
So, basically these are two quite distinct concepts. Unfortunately the Spring-Implementation of @resource has a built-in fallback, which kicks in when resolution by-name fails. In this case, it falls back to the @Autowired-kind resolution by-type. While this fallback is convenient, IMHO it causes a lot of confusion, because people are unaware of the conceptual difference and tend to use @resource for type-based autowiring.

@ddtxra
Copy link
Contributor Author

ddtxra commented Oct 6, 2014

@evaletolab
Copy link

An other solution with @Autowired (I don't know the limitation here) you can qualify you wiring :

   @Autowired
   InterfaceName  beanName

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

No branches or pull requests

2 participants