Results 1 to 3 of 3

Thread: How to setup static class in spring?

  1. #1
    Join Date
    Oct 2005
    Posts
    14

    Default 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. #2
    Join Date
    Aug 2004
    Location
    New York
    Posts
    168

    Default

    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.
    Karl Baum
    weblog: www.jroller.com/page/kbaum

  3. #3
    Join Date
    Aug 2004
    Location
    Amsterdam, Netherlands
    Posts
    450

    Default

    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
    Alef Arendsen
    SpringSource
    http://www.springsource.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •