Announcement Announcement Module
Collapse
No announcement yet.
Spring 3: adding <mvc:annotation-driven/> causes ClassCastException Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring 3: adding <mvc:annotation-driven/> causes ClassCastException

    Hi

    Reading the new Chapter 5 on Spring MVC, I decided to add
    <mvc:annotation-driven/> to my config in order to use validation mechanism @Valid.

    Code:
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
    	xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
    	xmlns:mvc="http://www.springframework.org/schema/mvc"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans 
    	http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
    	http://www.springframework.org/schema/context 
    	http://www.springframework.org/schema/context/spring-context-3.0.xsd 
    	http://www.springframework.org/schema/tx 
    	http://www.springframework.org/schema/tx/spring-tx-3.0.xsd 
    	http://www.springframework.org/schema/mvc 
    	http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd 
    	http://www.springframework.org/schema/aop 
    	http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
    
    	<mvc:annotation-driven/>
    ...
    And now, when loading the application, I get a ClassCastException. It is the ONLY change I've made to a working setup.

    Sorry for the long stacktrace...

    Any suggestion? Am I missing a JAR? or loading an incorrect one? I'm using Maven 3 to build.

    Everything worked fine until I added that <mvc:annotation-driven/>

    Thanks

    Benoit

    Code:
    09:04:30,244 ERROR [DispatcherServlet][main] Context initialization failed
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter#0': Cannot c
    eate inner bean '(inner bean)' of type [org.springframework.http.converter.ByteArrayHttpMessageConverter] while setting bean property 'messageConverters' with key [0]; nested exc
    ption is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#2': Initialization of bean failed; nested exception is java.lang.Cla
    sCastException: org.aspectj.weaver.ResolvedType$Array cannot be cast to org.aspectj.weaver.ReferenceType
            at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:281)
            at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:125)
            at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedList(BeanDefinitionValueResolver.java:355)
            at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:153)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1305)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1067)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:511)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)
            at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:290)
            at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
            at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:287)
            at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:189)
            at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:557)
            at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:842)
            at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:416)
            at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:443)
            at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:459)
            at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:340)
            at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:307)
            at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127)
            at javax.servlet.GenericServlet.init(GenericServlet.java:241)
            at org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:433)
            at org.mortbay.jetty.servlet.ServletHolder.doStart(ServletHolder.java:256)
            at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:40)
            at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:617)
            at org.mortbay.jetty.servlet.Context.startContext(Context.java:139)
            at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1218)
            at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:500)
            at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:448)
            at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:40)
            at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:147)
            at org.mortbay.jetty.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:161)
            at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:40)
            at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:147)
            at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:40)
            at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:117)
            at org.mortbay.jetty.Server.doStart(Server.java:210)
            at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:40)
            at org.mortbay.jetty.plugin.Jetty6PluginServer.start(Jetty6PluginServer.java:134)
            at org.mortbay.jetty.plugin.AbstractJettyMojo.startJetty(AbstractJettyMojo.java:341)
            at org.mortbay.jetty.plugin.AbstractJettyMojo.execute(AbstractJettyMojo.java:286)
            at org.mortbay.jetty.plugin.AbstractJettyRunMojo.execute(AbstractJettyRunMojo.java:195)
            at org.mortbay.jetty.plugin.Jetty6RunMojo.execute(Jetty6RunMojo.java:183)
            at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:105)
            at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:562)
            at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:317)
            at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:245)
            at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:102)
            at org.apache.maven.cli.MavenCli.execute(MavenCli.java:423)
            at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:158)
            at org.apache.maven.cli.MavenCli.main(MavenCli.java:123)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:597)
            at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
            at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
            at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
            at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#2': Initialization of bean failed; nested exception is java.lang.C
    ....

  • #2
    Solution...

    I think that I've answered my own question...

    I needed to update aspectJ, it was still using 1.5.4 and now I use:

    Code:
    <dependency>
         <groupId>org.aspectj</groupId>
         <artifactId>aspectjweaver</artifactId>
         <version>1.6.6</version>
         <scope>runtime</scope>
    </dependency>
    Et voila!

    Benoit

    Comment

    Working...
    X