Announcement Announcement Module
Collapse
No announcement yet.
How to setup static class in spring? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to setup static class in spring?

    I wrote a static util class for presentation tier.

    But this util class need invoke a method of one class in business tier which is not static.

    How can I set it in spring?

    Thanks

  • #2
    The problem with static classes is that they are not creating by the Spring container. If you want your static class to reference a spring configured bean, you need to explicitly get the bean by invoking getBean on a BeanFactory.

    Instead, I would suggest replacing your static utility class with a non-static utility class. Then your utility can be created by the spring container and you can leverage dependency injection to reference the business tier.

    Comment


    • #3
      If you still need the static class, you can lookup the context by using WebApplicationContextUtils. You'd need the servlet context though, but since the it's a presentation tier utility, I suspect you have that available somewhere...

      regards,
      Alef

      Comment

      Working...
      X