Announcement Announcement Module
Collapse
No announcement yet.
what is the best way to get ApplicationContext from inside of bean in web app? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • what is the best way to get ApplicationContext from inside of bean in web app?

    I need get resource with method ApplicationContext.getResource() but how can I get ApplicationContext in bean class in web app?
    edit: or any other method to get resource from classpath...
    Last edited by Juliusz; Jan 18th, 2011, 07:42 AM.

  • #2
    i'm also intrested into that.. Have you found a solution ?

    Comment


    • #3
      Originally posted by gaukler View Post
      i'm also intrested into that.. Have you found a solution ?
      I digged that it should be helpful WebApplicationContext interface (it extends ApplicationContext interface).

      To get this is static method getWebApplicationContext(ServletContext sc) of some util class: http://static.springsource.org/sprin...vletContext%29

      parameter ServletContext is available from implementing ServletContextAware interface in bean class that use getWebApplicationContext(..)

      edit: unfortunately servletContext in case ServletContextAware is equal null in constructor since I can't get Resource in bean constructor.

      edit2: unfortunately WebApplicationContext is null after this in bean init-method: WebApplicationContext webappctx = WebApplicationContextUtils.getWebApplicationContex t(servletContext); although servletContext there is not null
      Last edited by Juliusz; Jan 18th, 2011, 07:40 AM.

      Comment


      • #4
        Please help...

        Comment


        • #5
          You want to access the application context inside of a bean?

          Isn't implementing ApplicationContextAware helps?

          Comment


          • #6
            Originally posted by amiladomingo View Post
            You want to access the application context inside of a bean?

            Isn't implementing ApplicationContextAware helps?
            Thanks! This works perfectly.

            Comment

            Working...
            X