Announcement Announcement Module
Collapse
No announcement yet.
Getting servlet context in a web bundle deployed in dm server 2 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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, 07:01 AM.

  • #2
    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.

    Comment


    • #3
      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

      Comment


      • #4
        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>

        Comment


        • #5
          Thanks , It worked this way.


          Regards,
          Vishal

          Comment

          Working...
          X