Announcement Announcement Module
No announcement yet.
Two questions about bean design with spring framework Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Two questions about bean design with spring framework

    Hi all,

    I am a newbie to spring framework, I have two questions about spring bean design:

    1. What kind of java object should I put in bean config file or just use "new" to create it?

    2. When should I use dependency injection or just diectly call beanFactory to create it?

    Thanks a lot.

  • #2
    1. Typically the objects you configure as beans in the application context provide services to your application: DAOs, Service layer objects, Web Controllers, DataSources, ... It's not that common to have Spring manage your domain layer objects.

    2. Use DI whenever it's possible. It will avoid a dependency on Spring and just makes your code easier to use. Only directly use the application context in a "service locator" kind of way when DI can't work, e.g. when the collaborator is only known at runtime.



    • #3
      One more question, what kind of properties should I put in a spring context file or just put them in a separate key-value pair property file?
      Thanks a lot.