• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Spring: how to "produce" beans ?

 
Bartender
Posts: 1357
39
IBM DB2 Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As far as I know,  there are three ways to define Producers for a given bean:

a) you can annotate with @Service a POJO, and the POJO would be produced as singleton




b) you can define a Bean , annotate or not with Component (or other specialized annotations), and define a producer method in a @Configuration annotated class:




c) you may define a FactoryBean<T> extending class




What are, if any, the key differences between these approaches ?

 
Bartender
Posts: 1155
20
Mac OS X IntelliJ IDE Oracle Spring VI Editor Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Three ways to define beans;

1) Java Configuration (you have this as b), this is the preferred way; offers type safety, central location for configuration.
2) Component Scanning (a), quicker to write code (but harder to maintain - etc).
3) XML Configuration, verbose, no type safety.  

I'm not sure about your third option (c).

You are providing spring with bean configuration(s) and then it is creating the spring beans, and passing back a proxy to those beans.  
 
reply
    Bookmark Topic Watch Topic
  • New Topic