Announcement Announcement Module
No announcement yet.
Q: classname url mapping does not supports multiple xml contents Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Q: classname url mapping does not supports multiple xml contents

    Hello, I am just a newbie to spring world. I have some problems in configuring spring MVC. my problem is that classname url mapping bean defined in one xml file does not try to find beans in other xml.

    I tried to seperate config files by modules. ( ex. product / user / ...)
    so I made dispatcher-servlet.xml and product-web.xml , product-dao.xml, ... and put the bean definitions in each xml file and servlet loads it by context loader listener
    			/WEB-INF/applicationContext*.xml /WEB-INF/user*.xml
    I want to use both bean name url mapping and class name url mapping. so I put the definition in dispatcher-servlet.xml
    <bean id="beanNameUrlMapping"
    		<property name="order">
    	<bean id="classNameUrlMapping"
    		<property name="order">
    it works well when i put the controller definition in same xml file. this is the Controller definition.
    	<bean  id="listProduct"
    		<property name="mgr">
    			<ref bean="productManager" />
    this woks well when I access by /listproduct.htm because of class name url mapping. but if I move it to another xml file ( product-web.xml ), it fails.

    when I look at logs, the classname url mapping handler doesn't find "listProduct" . I think because it places in another xml file.

    My final solution was include product-web.xml into dispatcher-servlet.xml
    <import resource="/product-web.xml" />
    but it doesn't look good... is there any better solution for this problem?

  • #2
    It isn't the fact that it is in another xml file it is the fact that it is in another ApplicationContext. The BeanNameUrlHandlerMapping and ControllerClassNameHandlerMapping operate only on Controllers defined in the same application context.

    Which is logical because the Controller should be loaded by your Dispatcher-Servlet and not your ContextLoaderListener (your root app context) that should only contain (in general) your services/dao's etc not your controllers or web related stuff.


    • #3
      thanks! I undestand it and solved that problem.