• 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Carey Brown
  • Frits Walraven

Use of Bean Locator Pattern

Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anybody has used 'Bean Locator' pattern in their life?
I have searched experiences using this pattern and I have not found something.
Posts: 68857
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not heard of it; let's try duplicating this question in another forum where you might get more attention.
Posts: 21917
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Frameworks like Spring and CDI use it internally. You ask for a bean to be injected, and the framework will locate an appropriate instance and inject that. JNDI look-ups can probably also be seen as the bean locator pattern.
Saloon Keeper
Posts: 21941
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Bean Locator" is an implementation specific term. Patterns are supposed to be abstract, and what I suspect that what you are looking for is the Service Locator pattern.

Service Locators are resources that code can use to locate a particular set of functions, which are typically defined in terms of an Interface, although you can have a Service Locator return a concrete object as well.

I'll have to contest Rob's claim that resource frameworks such as Spring and CDI use Bean Locators internally. Those frameworks actually implement the Factory pattern and how they work internally is supposed to be opaque to their clients. In fact, it's common for them to keep their beans in an internal Map object (or chain of Maps), but that's purely their decision.

The lines are not clear-cut. A Service Locator is expected to return an existing interface/object, but there's no reason it cannot also manufacture one. I would, however expect a Service Locator to consistently return the same object, whereas a Factory has the option to return multiple instances of an object.

User-designed Factories generally return objects of only one or a small number of class/interface types. Systems like Spring are usually designed to return objects of many different types.

You could use a Service Locator to find a Factory, but in actual practice, the factory is typically a Singleton and located as a static class.
"I know this defies the law of gravity... but I never studied law." -B. Bunny Defiant tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
    Bookmark Topic Watch Topic
  • New Topic