calipho-sib / nextprot-api

neXtProt API - From SIB CALIPHO group; neXtProt project
https://api.nextprot.org
Other
16 stars 4 forks source link

Try using @Resource instead of @Autowire #7

Open ddtxra opened 10 years ago

ddtxra commented 10 years ago

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 commented 10 years ago

Using @Qualifier should also make the trick (3.9.3) http://docs.spring.io/spring/docs/3.0.x/spring-framework-reference/html/beans.html#beans-autowired-annotation-qualifiers

evaletolab commented 10 years ago

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

   @Autowired
   InterfaceName  beanName