Announcement Announcement Module
Collapse
No announcement yet.
Using @Controller mixed with Web Flow Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using @Controller mixed with Web Flow

    I'm trying to use a mix of MVC and Web Flow, where some urls should map to a simple @Controller and some urls should map to a flow.

    When I only implement the MVC part, the pages show as expected.

    Then I add the flow part. Now the pages that are part of the flow show as expected, but the 'plain' pages do not show anymore! (404 errors, no mapping found)

    I know that because I added the flowadapter and flowmapping, the default adapter etc. that were previously automatically supplied by Spring are now overwritten by the flowbeans. So, I should add the adapter and mapping myself now.

    This is what I came up with, but the annotation mapping does not work.
    Code:
    <servlet>
    		<servlet-name>xxx</servlet-name>
    		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    		<init-param>
    			<param-name>contextConfigLocation</param-name>
    			<param-value>/WEB-INF/controllers/xxx.xml</param-value>
    		</init-param>
    		<load-on-startup>1</load-on-startup>
    	</servlet>
    
    	<servlet-mapping>
    		<servlet-name>xxx</servlet-name>
    		<url-pattern>/secured/*</url-pattern>
    	</servlet-mapping>
    Code:
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:context="http://www.springframework.org/schema/context"
    	   xsi:schemaLocation="http://www.springframework.org/schema/beans
          		http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
           		http://www.springframework.org/schema/context 
           		http://www.springframework.org/schema/context/spring-context-2.5.xsd">
    	
    	<context:annotation-config />
    	
    	<context:component-scan base-package="xxx.web.controller" />
    	
    </beans>
    Code:
    <import resource="spring-webflow.xml" />
    
    	<!-- Enables annotated POJO @Controllers -->
    	<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
    
    	<!-- Enables plain Controllers -->
    	<bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" />
    
    	<!-- Enables FlowHandlers -->
    	<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter">
    		<property name="flowExecutor" ref="flowExecutor"/>
    	</bean>
    
    	<!-- URL to flow mapping rules -->			
    	<bean id="flowMappings" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    		<property name="mappings">
    			<value>
    				/xxx=xxx
    			</value>
    		</property>
    		<property name="order" value="1"/>
    	</bean>
    
    	<bean name="xxx"
    		class="xxx.web.webflow.xxxFlowHandler" />
    
    	<!-- Default mapping for Spring MVC -->
    	<bean
    		class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
    		<property name="order" value="2" />
    	</bean>
    
    	<bean id="viewResolver"
    		class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    		<property name="viewClass"
    			value="org.springframework.web.servlet.view.JstlView">
    		</property>
    		<property name="prefix" value="/WEB-INF/jsp/"></property>
    		<property name="suffix" value=".jsp"></property>
    	</bean>
    Code:
    @Controller
    public class HomeController {
    
    	@RequestMapping(value = "/home", method = RequestMethod.GET)
    	public ModelAndView home(HttpServletRequest request) {
     		return new ModelAndView("home");
    	}
    
    }
    The web flow configuration is a standard one and works, so I left it out here.

    When I try to visit http://localhost/appname/secured/home, I get the '[PageNotFound] No mapping found for HTTP request with URI [/appname/secured/home] in DispatcherServlet' case.
    (As I mentioned before, visiting the above url works without the web flow beans.)

    What am I missing here?


    It seems like it is solved now. I'm not really sure what the real reason is, but I think it is the config file referenced by the dispatcherservlet in web.xml. As in the reference app, I removed this reference and put the lines in that file in the general configuration file.
    Last edited by CalamityAce; Jun 25th, 2009, 05:13 AM. Reason: Solved
Working...
X