Announcement Announcement Module
Collapse
No announcement yet.
Calling DAO's from taglibs + filters Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Calling DAO's from taglibs + filters

    Hi all

    I tried looking for this but I couldnt find anything about my 2 problems.

    I have 2 problems. They basically come down to 1 problem.

    I have a couple of DAO's which I create in appplicationContext.xml. I ensure that the session factory bean is passed on as a parameter allowing that dao to execute hibernate queries etc using the session factory. When I create a controller bean I pass the neccessary DAO's on as parameters.

    The problem lies with filters that I create in web.xml and in taglibs. Somehow I need to access those DAO's created in applicationContext. If I say new TestDAO() then the session factory isnt initialized for that bean.

    I know of a way to load the DAO's by loading the applicationContext xml file and retreiving the DAO's from there but I'm worried that since that would take place more than 3 times each request the load on the server would be just too much.

    Has anybody got a solution on how to initialize the dao's from filters and taglibs?

  • #2
    You should write a controller that loads on servlet engine startup and populates the variables that you need.

    On load this will call a service class (or whatever mechanism you use) and then the service class will call the DAO to retrieve whatever variables you want pre-populated.

    Hope this helps!

    Originally posted by martyn at hi-ss DOT nl View Post
    I tried looking for this but I couldnt find anything about my 2 problems.

    I have 2 problems. They basically come down to 1 problem.

    I have a couple of DAO's which I create in appplicationContext.xml. I ensure that the session factory bean is passed on as a parameter allowing that dao to execute hibernate queries etc using the session factory. When I create a controller bean I pass the neccessary DAO's on as parameters.

    The problem lies with filters that I create in web.xml and in taglibs. Somehow I need to access those DAO's created in applicationContext. If I say new TestDAO() then the session factory isnt initialized for that bean.

    I know of a way to load the DAO's by loading the applicationContext xml file and retreiving the DAO's from there but I'm worried that since that would take place more than 3 times each request the load on the server would be just too much.

    Has anybody got a solution on how to initialize the dao's from filters and taglibs?

    Comment


    • #3
      You can configure your filters as Spring Beans. Take a look at the DelegatingFilterProxy, this allows you to configure your filters in the application context.

      Comment

      Working...
      X