Announcement Announcement Module
No announcement yet.
Bean with all static methods Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Bean with all static methods


    I have a simple Util class with few static methods. one of the method make use of DAO.

    so is it possible to convert this class as Spring Bean with same static methods. if possible how to inject my DAO into this.

    Please help me

  • #2
    You may run into issues of you are trying to do dependency injection through static members. Spring will throw an exception - Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyExcep tion: But it is possible to make this util class a Spring Bean.


    • #3
      Don't do that then

      There's little need to define a bean with all static methods. Just define it as an ordinary bean with ordinary instance methods, and either declare it in your application context file or annotate it with @Component. Then, only one instance of the class will ever be created, and you get the advantages of dependency injection.