Results 1 to 6 of 6

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

  1. #1
    Join Date
    Nov 2010
    Posts
    8

    Unhappy 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 at 06:42 AM.

  2. #2

    Default

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

  3. #3
    Join Date
    Nov 2010
    Posts
    8

    Default

    Quote 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 at 06:40 AM.

  4. #4
    Join Date
    Nov 2010
    Posts
    8

    Default

    Please help...

  5. #5
    Join Date
    Dec 2010
    Location
    Singapore
    Posts
    285

    Default

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

    Isn't implementing ApplicationContextAware helps?
    Amila Domingo

  6. #6
    Join Date
    Nov 2010
    Posts
    8

    Smile

    Quote 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.

Posting Permissions

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