Announcement Announcement Module
Collapse
No announcement yet.
Spring 3.2 - ClassCastException: ContentNegotiationManagerFactoryBean Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring 3.2 - ClassCastException: ContentNegotiationManagerFactoryBean

    Hi together,
    within my simple spring 3.2 application I have the following configuration:

    Code:
    public abstract class AbstractWebAppInitializer implements WebApplicationInitializer {
    	
    
    	@Override
    	public void onStartup(ServletContext servletContext) throws ServletException {
    		AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    		rootContext.register(getRootConfig());
    		servletContext.addListener(new ContextLoaderListener(rootContext));
    		
    		AnnotationConfigWebApplicationContext mvcContext = new AnnotationConfigWebApplicationContext();
    		mvcContext.register(getWebConfig());
    		Dynamic appServlet = servletContext.addServlet("appServlet", new DispatcherServlet(mvcContext));
    		appServlet.setLoadOnStartup(1);
    		appServlet.addMapping("/web/*");
    	}
    ...
    }
    When I run my jetty8 container, I got the following exception. Within my classpath, I do not have any different spring jars.

    Code:
    SEVERE: Context initialization failed
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration.class]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.requestMappingHandlerMapping()] threw exception; nested exception is java.lang.ClassCastException: org.springframework.web.accept.ContentNegotiationManagerFactoryBean$$EnhancerByCGLIB$$1b0458f8 cannot be cast to org.springframework.web.accept.ContentNegotiationManager
    	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:581)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1029)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:925)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:490)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:607)
    	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
    	at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:647)
    	at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:504)
    	at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:458)
    	at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:138)
    	at javax.servlet.GenericServlet.init(GenericServlet.java:242)
    	at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:519)
    	at org.eclipse.jetty.servlet.ServletHolder.doStart(ServletHolder.java:331)
    	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
    	at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:747)
    	at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:265)
    	at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1250)
    	at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:706)
    	at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:492)
    	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
    	at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:95)
    	at org.eclipse.jetty.server.Server.doStart(Server.java:277)
    	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
    	at runjettyrun.Bootstrap.main(Bootstrap.java:80)
    Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.requestMappingHandlerMapping()] threw exception; nested exception is java.lang.ClassCastException: org.springframework.web.accept.ContentNegotiationManagerFactoryBean$$EnhancerByCGLIB$$1b0458f8 cannot be cast to org.springframework.web.accept.ContentNegotiationManager
    	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:181)
    	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:570)
    	... 29 more
    Caused by: java.lang.ClassCastException: org.springframework.web.accept.ContentNegotiationManagerFactoryBean$$EnhancerByCGLIB$$1b0458f8 cannot be cast to org.springframework.web.accept.ContentNegotiationManager
    	at org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration$$EnhancerByCGLIB$$90e838a4.mvcContentNegotiationManager(<generated>)
    	at org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.requestMappingHandlerMapping(WebMvcConfigurationSupport.java:198)
    	at org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration$$EnhancerByCGLIB$$90e838a4.CGLIB$requestMappingHandlerMapping$17(<generated>)
    	at org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration$$EnhancerByCGLIB$$90e838a4$$FastClassByCGLIB$$8fac2457.invoke(<generated>)
    	at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
    	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:285)
    	at org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration$$EnhancerByCGLIB$$90e838a4.requestMappingHandlerMapping(<generated>)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:601)
    	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:160)
    	... 30 more


    Any idea?
    Thanks for your help!

  • #2
    I finally found the error, I was including a xml-config with <mvc:annotation-driven/>... I removed this, now it works

    Comment


    • #3
      Originally posted by fritzr View Post
      I finally found the error, I was including a xml-config with <mvc:annotation-driven/>... I removed this, now it works
      Thank you so much! This was it for me also.. I even registered an account here just to thank you!

      Comment


      • #4
        Thanks

        Originally posted by fritzr View Post
        I finally found the error, I was including a xml-config with <mvc:annotation-driven/>... I removed this, now it works
        Thanks. I was facing the same problem. I am new to Spring so could you please let me know we removing that tag made a difference ?

        Comment

        Working...
        X