Announcement Announcement Module
Collapse
No announcement yet.
Q: classname url mapping does not supports multiple xml contents Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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
    Code:
    	<context-param>
    		<param-name>contextConfigLocation</param-name>
    		<param-value>
    			/WEB-INF/applicationContext*.xml /WEB-INF/user*.xml
    			/WEB-INF/product-*.xml
    		</param-value>
    	</context-param>
    	<listener>
    		<listener-class>
    			org.springframework.web.context.ContextLoaderListener
    		</listener-class>
    	</listener>
    I want to use both bean name url mapping and class name url mapping. so I put the definition in dispatcher-servlet.xml
    Code:
    <bean id="beanNameUrlMapping"
    		class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping">
    		<property name="order">
    			<value>1</value>
    		</property>
    	</bean>
    
    	<bean id="classNameUrlMapping"
    		class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping">
    		<property name="order">
    			<value>2</value>
    		</property>
    	</bean>
    it works well when i put the controller definition in same xml file. this is the Controller definition.
    Code:
    	<bean  id="listProduct"
    		class="pktroot.product.ListProductController">
    		<property name="mgr">
    			<ref bean="productManager" />
    		</property>
    	</bean>
    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
    Code:
    <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.

    Comment


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

      Comment

      Working...
      X