Results 1 to 5 of 5

Thread: Getting servlet context in a web bundle deployed in dm server 2

  1. #1
    Join Date
    Nov 2008
    Posts
    232

    Default Getting servlet context in a web bundle deployed in dm server 2

    Hi,
    Previously i used to get the servlet context from WebApplicationContext in my bean implementing ApplicationContextAware

    Code:
    public class ApplicationContextHelper implements ApplicationContextAware{
    
    	private static WebApplicationContext ctx;
    
    	  public void setApplicationContext(ApplicationContext ctx) throws BeansException {
    		 ApplicationContextHelper.ctx = (WebApplicationContext)ctx;
    	  }
    		
    	  public static ServletContext getContext() {
    	    ServletContext servletContext = ctx.getServletContext();
    	    return servletContext;
    	  }
    
    	
    	
    }

    Now the code gives me ClassCastException
    Code:
    java.lang.ClassCastException: org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext cannot be cast to org.springframework.web.context.WebApplicationContext
    All i want is getting servletContext in my spring beans
    Last edited by vishalj; Jan 12th, 2010 at 06:01 AM.

  2. #2
    Join Date
    Dec 2005
    Location
    Philadelphia, PA, USA
    Posts
    228

    Default

    Can you provide some extra info:

    1. How is your web.xml is configured? i.e. what is you context class name
    2. Where are you spring context files? i.e. in META-INF/spring or somewhere else
    3. What version fo dm-server you are running.
    Thanks
    Dmitry

  3. #3
    Join Date
    Nov 2008
    Posts
    232

    Default

    1.Context class in web.xml:
    Code:
    	<context-param>
    		<param-name>contextClass</param-name>
    		<param-value>com.springsource.server.web.dm.ServerOsgiBundleXmlWebApplicationContext</param-value>
    	</context-param>
    2.My context xml's are placed under META-INF/spring

    3. I am running my web-app under springsource-dm-server-2.0.0.RC1

    Regards,
    Vishal

  4. #4
    Join Date
    Dec 2005
    Location
    Philadelphia, PA, USA
    Posts
    228

    Default

    I believe that by placing the files under /META-INF/spring - your context files are processed by spring-dm extender vs. the context class that you specified.

    Try to place the contexts under WEB-INF/ and specify the config this way:

    Code:
    <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>
                /WEB-INF/spring/context/*.xml
            </param-value>
        </context-param>
    
        <context-param>
            <param-name>contextClass</param-name>
            <param-value>com.springsource.server.web.dm.ServerOsgiBundleXmlWebApplicationContext</param-value>
        </context-param>
    
    
        <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>
    Thanks
    Dmitry

  5. #5
    Join Date
    Nov 2008
    Posts
    232

    Default

    Thanks , It worked this way.


    Regards,
    Vishal

Posting Permissions

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