Announcement Announcement Module
Collapse
No announcement yet.
Problem with metadata for MVC Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with metadata for MVC

    I'm having a problem which I can't seem to solve.

    I read through chapter 8 of the Spring reference guide and tried to implement - for starters - the handler mapping for one of my controllers as described in section 8.5. I added the following line to my controller:

    Code:
    @@org.springframework.web.servlet.handler.metadata.PathMap("/ca.ctrl")
    I then added the proper CommonsPathMapHandlerMapping entry to my xml config file. Did the ant task and everything compiled fine. Then jar'd and indexed and deployed. When the app starts up I get this error:

    Code:
    [05/08/05-14:18 ERROR FrameworkServlet.initServletBean] Context initialization failed
    org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.test.web.section.content.admin.controller.ContentAdminController' defined in null: Unsatisfied dependency expressed through bean property 'delegate': There are 118 beans of type [class java.lang.Object] for autowire by type. There should have been 1 to be able to autowire property 'delegate' of bean 'com.test.web.section.content.admin.controller.ContentAdminController'.
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireByType(AbstractAutowireCapableBeanFactory.java:754)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:673)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowire(AbstractAutowireCapableBeanFactory.java:160)
            at org.springframework.web.servlet.handler.metadata.AbstractPathMapHandlerMapping.initApplicationContext(AbstractPathMapHandlerMapping.java:128)
            at org.springframework.context.support.ApplicationObjectSupport.setApplicationContext(ApplicationObjectSupport.java:89)
            at org.springframework.context.support.ApplicationContextAwareProcessor.postProcessBeforeInitialization(ApplicationContextAwareProcessor.java:80)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:204)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:342)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:260)
            at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:221)
            at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:145)
            at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:282)
            at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:317)
            at org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.refresh(AbstractRefreshableWebApplicationContext.java:131)
            at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:303)
            at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:250)
            at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:219)
            at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:111)
            at javax.servlet.GenericServlet.init(GenericServlet.java:211)
            at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1029)
            at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:862)
            at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4013)
            at org.apache.catalina.core.StandardContext.start(StandardContext.java:4357)
            at org.apache.catalina.core.StandardContext.reload(StandardContext.java:3043)
            at org.apache.catalina.core.StandardContext.backgroundProcess(StandardContext.java:4658)
            at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1619)
            at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1628)
            at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1628)
            at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1608)
            at java.lang.Thread.run(Thread.java:613)
    I dug through all the Spring source including the exceptions to see if I could get some clue as to what it's actually saying. But I couldn't figure anything out. If I could get this to work, I'd love to do all my controller and service defs thru metadata as I feel it's much easier to deal with than a ton of xml entries. However, even on the most basic example, I can't seem to figure it out.

    I still have my xxx-servlet.xml entries which work fine when I disable the metdata stuff.

    Any help would be appreciated. Thx.

  • #2
    The error message is telling you that your controller has a property 'delegate' of type java.lang.Object. Spring needs to be able to autowire the dependencies of controllers defined by metadata attributes, so it is important that there is only one bean of the dependent object type (here java.lang.Object) defined in the XML bean definitions. You seem to have lots (118 in fact). Can't say any more than that without seeing to source :-)

    Comment


    • #3
      Right.

      The problem - at least for me - is that this section of the docs (for MVC and metadata) is very sparse and the examples are very generic. In fact, there's only one example and it's just a snippet.

      Anyway, it's saying I have 118 objects cuz, basically, thru all my xml def files (servlet, service, dao - I've broken all my object types into their own files) I have 118 beans declared. And while I def. appreciate your answer, I do understand the fact that the container is trying to wire up the constructor of my controller, which is a subclass of MultiActionController which in its constructor calls the delegate(Object) method which is in turn causing my error msg.

      However, that's the part I'm trying to figure out. The Commons attribute docs doesn't say much about how to really use these annotated features. Do I create another constructor that accepts an Object and hand it up to the MultiActionController so it can set the delegate? Or is there some way I can do this thru the attributes themselves?

      While I feel there is definitely better docs and support for this sort of thing at the transaction level, there is not much at the web level, which for me, has much more XML config code and is thusly where I'd really like to use this. In my case, I won't ever need to modify the XML at the web level, so I'd love to have all my config defined as attributes and have the framework deal with it.

      Guess I'll keep digging and maybe I'll find the answer somehow. Thx.

      Comment

      Working...
      X