• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

@Resource is able to autodetect by type

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

Based on what I've read on @Resource annotation, it's DI is by-Name. However, using a bean that's named differently from its setter method (Bean: resourceDependencyTwo vs Setter: resourceDependency) also worked.

Isn't this a contradiction ?

Please check the following:




Dependent Resource:



Dependency:





....##MAIN

ResourceDependent da = (ResourceDependent) context.getBean("resourceDependent");
da.executeDependency();


OUTPUT:
Message from Dependency:Chuck!
 
Izanami Caster
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just found this in the spring.io documentation:

Similar to @Autowired, @Resource may fall back to standard bean type matches (i.e. find a primary type match instead of a specific named bean) as well as resolve well-known "resolvable dependencies": the BeanFactory interface, the ApplicationContext interface, the ResourceLoader interface, the ApplicationEventPublisher interface and the MessageSource interface. Note that this only applies to @Resource usage with no explicit name specified!


Ref:https://docs.spring.io/spring-framework/docs/3.0.0.M3/reference/html/ch04s11.html

I've found my answer.

Thanks,
IC
 
reply
    Bookmark Topic Watch Topic
  • New Topic