Announcement Announcement Module
Collapse
No announcement yet.
Unable to add Surf to an existing Spring MVC web application Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Unable to add Surf to an existing Spring MVC web application

    I'm using this sample application which at the end of the tutorial gives you instructions to checkout the source from Subversion. Build and deploy to a container and you will have an existing Spring MVC webapp.

    http://www.springbyexample.org/examp...ig-webapp.html

    The subversion URL and command is:
    svn co http://svn.springbyexample.org/web/s...bapp/tags/1.1/ simple-form-annotation-config-webapp

    If you deploy that app, all is well and the webapp runs smoothly.

    I then go to the root of the project and launch my Roo command-line and type the following to install Surf 1.0.0-M3.

    surf install

    Roo creates everything required for Surf.

    When I start the application with these results I get the following error in my Tomcat logs (Tomcat version 6.0.26).

    Sep 21 2010 20:57:38 DEBUG org.springframework.beans.TypeConverterDelegate - Cannot create copy of Collection type [java.util.ArrayList] - injecting original Collection as-is
    java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Collection

    There are two issues here (potentially more) that is causing the app to completely crash at deployment time:

    1.) You will see that the web.xml now has two declarations and mappings for the DispatcherServlet. I tried to combine these into a servlet declaration which has a url-mapping for surf specific pages and springmvc specific pages. That did not work

    2.) Before running 'surf install' at the roo command-line, I renamed the original springmvc spring file from web-application-context.xml to web-application-config.xml in hope that roo would 'manage' this file and add what's needed. Rather than 'manage' this file, it completely stepped all over it and overwrote it with what's required for surf. All of the original configuration for the springmvc app was deleted.


    Here is my resulting web.xml file:

    Code:
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="WebApp_ID" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee                               http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
                                 
      <display-name>simple-form</display-name>
        
      <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
      </listener>
    
      <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/config/web-application-config.xml</param-value>
      </context-param>
    
      <filter>
        <filter-name>encoding-filter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
          <param-name>encoding</param-name>
          <param-value>UTF-8</param-value>
        </init-param>
      </filter>
    
      <filter-mapping>
        <filter-name>encoding-filter</filter-name>
        <url-pattern>/*</url-pattern>
      </filter-mapping>
    
      <servlet>
        <servlet-name>simple-form</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
          <param-name>contextConfigLocation</param-name>
          <param-value/>
        </init-param>
      </servlet>
        
      <servlet-mapping>
        <servlet-name>simple-form</servlet-name>
        <url-pattern>*.html</url-pattern>
      </servlet-mapping>
      <servlet-mapping>
        <servlet-name>simple-form</servlet-name>
        <url-pattern>/page/*</url-pattern>
      </servlet-mapping>
        
      <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
      </welcome-file-list>
    
      <filter>
        <filter-name>UrlRewriteFilter</filter-name>
        <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
      </filter>
      <filter-mapping>
        <filter-name>UrlRewriteFilter</filter-name>
        <url-pattern>/*</url-pattern>
      </filter-mapping>
    </web-app>
    Please advise on how we can use Spring 3.0, annotated Spring MVC with Surf so both play nice in a single web application.

    Thanks!

    - Billy -

  • #2
    I've managed to use annotated Spring MVC controllers with Surf by using the surf roo created web.xml etc. By default it gives you an annotated handler mapping bean in one of the config files it creates. Getting URLs to be handled correctly can take a bit of tweaking the urlrewrite.xml and handler mappings though. If you take a look at the config files in the WCM quickstart webapp available in the nighly build of Alfresco 3.4 then it might give you some ideas: http://dev.alfresco.com/downloads/ni...cmqs-3.4.a.zip - look in wcmqs.war at the config files in WEB-INF and WEB-INF/classes and it may give you some ideas. Also this wiki (which is still in progress - note the comments at the top of the page) may help... http://wiki.alfresco.com/wiki/WCM_Qu...eb_Application

    Comment


    • #3
      Thanks so much for the response chris, I've taken a look at what you've suggested.

      It appears that the alfresco wcm configs that you were referring to are identical to what 'surf install' gives you when you run it from roo (there are a bunch of other beans but I think for what I'm trying to get working, roo provides everything I need). I've reverted back to what roo has provided.

      So I'm still unable to get an annotated controller to execute. Could you take a quick glance at these relevant files and let me know what I have mis-configured? When the webapp deploys, I don't see any logs indicating that it has picked up my annotated controller and 'mapped' it to a specific URL.

      My web-application-config.xml:

      Code:
      <?xml version="1.0" encoding="UTF-8"?>
      <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"
      	xmlns:jdbc="http://www.springframework.org/schema/jdbc"
      	xmlns:tx="http://www.springframework.org/schema/tx"
      	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/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
      		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
      
        <!-- SURF: required infrastructure imports -->
      	<import resource="surf-config.xml"/>
      	
      	<!-- Maps requests to @Controllers based on @RequestMapping("path") annotation values
      		 If no annotation-based path mapping is found, Spring MVC sends a 404 response and logs a pageNotFound warning. -->
      	<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
      		<property name="order" value="1" />
      		
      		 <!--SURF: required interceptors -->
              <property name="interceptors">
                  <list>
                  	<ref bean="requestContextInterceptor"/>
                  	<ref bean="themeInterceptor"/>
                    <ref bean="previewContextInterceptor"/>
                  </list>
              </property>    
      	</bean>
      
      	<!-- SURF: interoperability with annotated controllers -->
      	<!-- Enables annotated @Controllers; responsible for invoking an annotated POJO @Controller when one is mapped. -->
      	<bean id="annotationMethodHandlerAdapter" class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>
      	
      	<!-- SURF: interoperability with simple controllers -->
      	<!-- Support for Default Surf Controllers -->
      	<bean id="simpleControllerHandlerAdapter" class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"/>	
      	
      	<!-- Configures Apache Commons Fileupload -->
      	<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
       		<property name="maxUploadSize" value="10000000"/>
      	</bean>
      
      </beans>
      My urlrewrite.xml file:

      Code:
      <?xml version="1.0" encoding="utf-8"?>
      <!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 3.0//EN" "http://tuckey.org/res/dtds/urlrewrite3.0.dtd">
      <urlrewrite default-match-type="wildcard">
      
      	<!-- Spring Surf -->
      	<rule>
      		<from>/proxy**</from>
      		<to>/service/proxy/$1</to>
      	</rule>
      	<rule>
      		<from>/res/**</from>
      		<to>/service/resource/$1</to>
      	</rule>		
      	<rule>
      		<from>/service/**</from>
      		<to>/service/$1</to>
      	</rule>		
      
      	<rule>
      		<from>/**/prodDetails/**</from>
      		<to>/service/ProductDetailsPage?prodid=$1</to>
      	</rule>			
      	<rule>
      		<from>/**</from>
      		<to>/service/$1</to>
      	</rule>
      	<outbound-rule>
      		<from>/service/**</from>
      		<to>/$1</to>
      	</outbound-rule>
      		
      </urlrewrite>
      My surf-config.xml:

      Code:
      <?xml version="1.0" encoding="UTF-8"?>
      <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-3.0.xsd
                 http://www.springframework.org/schema/context
                 http://www.springframework.org/schema/context/spring-context-3.0.xsd">
      
      	<!-- Import Web Scripts Framework -->
      	<import resource="classpath*:org/springframework/extensions/webscripts/*-context.xml" />
      	
      	<!-- Import Surf Framework -->
      	<import resource="classpath*:org/springframework/extensions/surf/*-context.xml" />
      	
         	<!-- Set up to auto-resolve to url based views -->   	
          <bean id="handlerMappings" parent="webframeworkHandlerMappings">
              <property name="order" value="0" />
      
              <!-- Remove the default handler for interoperability with other handlers -->
          	<property name="defaultHandler">
          		<bean class="org.springframework.web.servlet.mvc.UrlFilenameViewController" />
          	</property>
          </bean>
      
      </beans>
      My annotated controller:

      Code:
      package com.soundstrue.directweb.spring.controller;
      
      import com.soundstrue.directweb.Person;
      
      import org.apache.commons.logging.Log;
      import org.apache.commons.logging.LogFactory;
      
      import org.springframework.stereotype.Controller;
      import org.springframework.web.bind.annotation.ModelAttribute;
      import org.springframework.web.bind.annotation.RequestMapping;
      import org.springframework.web.bind.annotation.RequestMethod;
      import org.springframework.web.bind.annotation.RequestParam;
      
      /**
       *
       * @version 1.0
       * @since Sep 20, 2010
       */
      @Controller
      public class LoginController {
      
          protected final Log logger = LogFactory.getLog(getClass());
      
          /**
           * For every request for this controller, this will
           * create a person instance for the form.
           */
          @ModelAttribute
          public Person newRequest(@RequestParam(required=false) Integer id) {
              logger.debug("public Person newRequest(Integer id)");
      
              return (new Person());
          }
      
          /**
           * <p>Person form request.</p>
           *
           * <p>Expected HTTP GET and request '/person/form'.</p>
           */
          @RequestMapping(value="/person/form", method=RequestMethod.GET)
          public void form() {
              logger.debug("public void form() method");
          }
      }
      When I try to hit the following URL I receive a 404:

      http://localhost:8080/directweb/person/form

      Comment


      • #4
        If you haven't already then you either need the controller bean defined in the context file or to enable auto-scanning, eg

        <context:component-scan base-package="com.soundstrue.directweb.spring"/>

        Comment


        • #5
          I did try the auto-scanning with the following

          Code:
          <context:component-scan base-package="com.soundstrue.directweb.spring.controller"/>
          My controller lives in that package with the @Controller annotation. No luck at all with that. There must be something else I'm missing here.

          I did find this log statement which is concerning; maybe the reason why my controller is not getting executed? Why would this be happening?

          INFO : org.springframework.beans.factory.support.DefaultL istableBeanFactory - Overriding bean definition for bean 'loginController': replacing [Generic bean: class [com.soundstrue.directweb.spring.controller.LoginCo ntroller]; scope=singleton; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in file [/Users/bbacon/workspace/st/ecommerce/st-directweb/target/directweb/WEB-INF/classes/com/soundstrue/directweb/spring/controller/LoginController.class]] with [Generic bean: class [org.springframework.extensions.surf.mvc.LoginContr oller]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in URL [jar:file:/Users/bbacon/workspace/st/ecommerce/st-directweb/target/directweb/WEB-INF/lib/spring-surf-1.0.0.M3.jar!/org/springframework/extensions/surf/spring-surf-mvc-context.xml]]

          Comment


          • #6
            Ok, so I made a little bit of progress by simply renaming my 'LoginController' to 'LoginSpringMVCController'. I also put the auto-scanning spring configuration back into my web-application-config.xml file.

            Now when I deploy the application I see this in my logs (note I've simplified the RequestMapping URL just trying to get something to catch)...

            INFO : org.springframework.web.servlet.mvc.annotation.Def aultAnnotationHandlerMapping - Mapped URL path [/helloworld] onto handler [com.soundstrue.directweb.spring.controller.LoginSp ringMVCController@37f8883a]
            INFO : org.springframework.web.servlet.mvc.annotation.Def aultAnnotationHandlerMapping - Mapped URL path [/helloworld.*] onto handler [com.soundstrue.directweb.spring.controller.LoginSp ringMVCController@37f8883a]
            INFO : org.springframework.web.servlet.mvc.annotation.Def aultAnnotationHandlerMapping - Mapped URL path [/helloworld/] onto handler [com.soundstrue.directweb.spring.controller.LoginSp ringMVCController@37f8883a]

            So now it appears that Spring and the DispatcherServlet know about my annotated controller but I still cannot get the controller to execute with the following:

            http://localhost:8080/directweb/service/helloworld

            I get the following error:

            javax.servlet.ServletException: Could not resolve view with name 'helloworld' in servlet with name 'Spring Dispatcher Servlet'

            How can I have Surf serve certain URLs and have SpringMVC serve other URLs without any Surf involvement whatsoever?

            Here's my web.xml which sends everything through the DispatcherServlet after the urlrewrite.xml rule is applied to send everything (/**) to /service/*

            Code:
            <?xml version="1.0" encoding="UTF-8"?>
            <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
            	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
            	
              <display-name>Spring Surf Application</display-name>
            
              <context-param>
                <param-name>contextConfigLocation</param-name>
                <param-value>
                  classpath*:/spring-config.xml
                  /WEB-INF/config/web-application-config.xml
                </param-value>
              </context-param>
            
              <context-param>
                <param-name>konakart.properties</param-name>
                <param-value>konakart.properties</param-value>
              </context-param>
            
              <context-param>
                <param-name>konakart_app.properties</param-name>
                <param-value>konakart_app.properties</param-value>
              </context-param>
            
            
              <listener>
                <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
              </listener>
              <listener>
                <listener-class>com.soundstrue.listener.SoundsTrueApplicationListener</listener-class>
              </listener>
              <listener>
                <listener-class>com.soundstrue.listener.KonakartApplicationListener</listener-class>
              </listener>
            
                
              <!-- Enables clean URLs with JSP views e.g. /welcome instead of /page/welcome -->
              <filter>
                <filter-name>UrlRewriteFilter</filter-name>
                <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
              </filter>
            
              <filter-mapping>
                <filter-name>UrlRewriteFilter</filter-name>
                <url-pattern>/*</url-pattern>
              </filter-mapping>
            
            	<!-- Spring MVC Dispatcher Servlet -->
              <servlet>
                <servlet-name>Spring Dispatcher Servlet</servlet-name>
                <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
                <init-param>
                  <param-name>contextConfigLocation</param-name>
                  <param-value><!-- Leave this empty otherwise spring will blow-up --></param-value>
                </init-param>
                <load-on-startup>1</load-on-startup>
              </servlet>
              <servlet-mapping>
                <servlet-name>Spring Dispatcher Servlet</servlet-name>
                <url-pattern>/service/*</url-pattern>
              </servlet-mapping>
            
              <session-config>
                <session-timeout>30</session-timeout>
              </session-config>
            
            </web-app>
            And my urlrewrite.xml file again:

            Code:
            <?xml version="1.0" encoding="utf-8"?>
            <!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 3.0//EN" "http://tuckey.org/res/dtds/urlrewrite3.0.dtd">
            <urlrewrite default-match-type="wildcard">
            
            	<!-- Spring Surf -->
            	<rule>
            		<from>/proxy**</from>
            		<to>/service/proxy/$1</to>
            	</rule>
            <rule>
            		<from>/js/**</from>
            		<to>/js/$1</to>
            	</rule>
            	<rule>
            		<from>/images/**</from>
            		<to>/images/$1</to>
            	</rule>
            		<rule>
            		<from>/css/**</from>
            		<to>/css/$1</to>
            	</rule>
            	<rule>
            		<from>/res/**</from>
            		<to>/service/resource/$1</to>
            	</rule>		
            	<rule>
            		<from>/service/**</from>
            		<to>/service/$1</to>
            	</rule>		
            
            	<rule>
            		<from>/**/prodDetails/**</from>
            		<to>/service/ProductDetailsPage?prodId=$1</to>
            	</rule>			
            	<rule>
            		<from>/**</from>
            		<to>/service/$1</to>
            	</rule>
            	<outbound-rule>
            		<from>/service/**</from>
            		<to>/$1</to>
            	</outbound-rule>
            </urlrewrite>
            Is there any way to get my SpringMVC controller to execute and forward to a JSP for certain URLs and not have Surf try to handle things?

            Comment


            • #7
              Hi again. I was using page level Spring MVC controllers with some of my Surf pages (which also had Surf Webscript controllers for some of the components on the page). I can think of a couple of directions you could go:
              1. Write a custom PageViewResolver class (check the Surf source for the standard one) which forwards to your JSPs. This obviously still has your Spring MVC classes being processed by Surf. The class has two methods - one to decide if it will handle the particular URL and one to return a Surf PageView object. The PageView could then somehow render the JSPs without too much Surf involvement....my knowledge all gets a bit hazy here... so not 100% sure and this would need some experimentation and might not be the best way etc.
              2. Separate servlet dispatchers for Spring MVC and Surf if its possible to keep the context xml separate which is where I think you started. I don't know why that wasn't working but it feels like it should.
              3. Erm.... there may be a another way of using JSP rendering which bypasses much of the Surf stuff. I'll have a think when I'm more awake.

              Why do you need the separation of Spring MVC and Surf by the way?

              Comment


              • #8
                Thanks for the continued replies here, I really appreciate it.

                The main reason we would like the separation is because we would like to stay in SpringMVC / JSP for most of our web site but need Surf for just a few components that are pulled in dynamically from other channels which are written in PHP. This Surf/PHP/Webscript/Freemarker area seems to be working but we need to convert the rest of our site to this framework, which is currently written in a very dated web framework, Struts 1.2.9.

                Another developer on our team posted THIS which lead us to believe that we couldn't fully use JSPs (localization, form beans, etc) with a Java based Webscript. We do have a Java webscript forwarding to a Freemarker template but it doesn't feel very clean and there's a lot of manual population that we had to do. For example, to make our localization properties file (key/value pairs) available to the Freemarker template we need to add the ResourceBundle to the model on every request. SpringMVC/JSP/JSTL would give us this for free in a sense (with taglibs).

                Maybe we are going about this the wrong way? Point #1 you make below sounds interesting but I'm not entirely sure where to start there. I have one idea for point #2 below which I will experiment with and post again with the result. If you do come up with a #3 option, please let me know.

                Thanks a ton.

                Comment


                • #9
                  I've been experimenting with number 2 but haven't got very far. I tried putting together the sample surf app and a spring mvc app that I had lying around. I thought something like this might work...

                  Code:
                  	 <servlet>
                  		<servlet-name>surf-servlet</servlet-name>
                  		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
                  		<init-param>
                  			<param-name>contextConfigLocation</param-name>
                  			<param-value>/WEB-INF/config/web-application-config.xml</param-value>
                  		</init-param>
                  		<load-on-startup>1</load-on-startup>
                  	 </servlet>
                  	 <servlet>
                  	  	<servlet-name>spring-mvc</servlet-name>
                  	  	<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
                  		<init-param>
                  			<param-name>contextConfigLocation</param-name>
                  			<param-value>/WEB-INF/springconfig/cdlibrary-servlet.xml</param-value>
                  		</init-param>	  	
                  	 </servlet>
                  
                  	 <servlet-mapping>
                  		<servlet-name>surf-servlet</servlet-name>
                  		<url-pattern>/service/surf/*</url-pattern>
                  	 </servlet-mapping>
                  	 <servlet-mapping>
                  	  	<servlet-name>spring-mvc</servlet-name>
                  	  	<url-pattern>/service/spring/*</url-pattern>
                  	 </servlet-mapping>
                  Unfortunately my spring mvc app is written for Spring 2.5 and I'm getting various errors due to that and the path changes. I've run out of time for this evening...

                  Comment


                  • #10
                    Alright, so here's what I seem to have working and provides the separation I think we are looking for.

                    I had to completely separate each spring configuration file in order to have 2 Dispatcher Servlets configured, one for Surf and one for SpringMVC. We actually have 3 spring configurations declared here, the first one is what we need to load our persistence beans through Springs ContextLoaderListener.

                    Notice the separate Dispatcher Servlet entries with their own contextConfigLocation file.

                    Code:
                    <?xml version="1.0" encoding="UTF-8"?>
                    <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
                        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
                        
                      <display-name>Spring Surf Application</display-name>
                    
                      <context-param>
                        <param-name>contextConfigLocation</param-name>
                        <param-value>
                          classpath*:/spring-config.xml
                        </param-value>
                      </context-param>
                    
                      <context-param>
                        <param-name>konakart.properties</param-name>
                        <param-value>konakart.properties</param-value>
                      </context-param>
                    
                      <context-param>
                        <param-name>konakart_app.properties</param-name>
                        <param-value>konakart_app.properties</param-value>
                      </context-param>
                    
                      <listener>
                        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
                      </listener>
                      <listener>
                        <listener-class>com.soundstrue.listener.SoundsTrueApplicationListener</listener-class>
                      </listener>
                      <listener>
                        <listener-class>com.soundstrue.listener.KonakartApplicationListener</listener-class>
                      </listener>
                    
                        
                      <!-- Enables clean URLs with JSP views e.g. /welcome instead of /page/welcome -->
                      <filter>
                        <filter-name>UrlRewriteFilter</filter-name>
                        <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
                      </filter>
                    
                      <filter-mapping>
                        <filter-name>UrlRewriteFilter</filter-name>
                        <url-pattern>/*</url-pattern>
                      </filter-mapping>
                    
                      <servlet>
                        <servlet-name>Spring Surf Dispatcher Servlet</servlet-name>
                        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
                        <init-param>
                          <param-name>contextConfigLocation</param-name>
                          <param-value>/WEB-INF/config/web-application-surf-config.xml</param-value>
                        </init-param>
                        <load-on-startup>1</load-on-startup>
                      </servlet>
                      <servlet-mapping>
                        <servlet-name>Spring Surf Dispatcher Servlet</servlet-name>
                        <url-pattern>/service/*</url-pattern>
                      </servlet-mapping>
                    
                      <servlet>
                        <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
                        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
                        <init-param>
                          <param-name>contextConfigLocation</param-name>
                          <param-value>/WEB-INF/config/web-application-mvc-config.xml</param-value>
                        </init-param>
                        <load-on-startup>2</load-on-startup>
                      </servlet>
                      <servlet-mapping>
                        <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
                        <url-pattern>/mvc/*</url-pattern>
                      </servlet-mapping>
                    
                      <session-config>
                        <session-timeout>30</session-timeout>
                      </session-config>
                    
                    </web-app>
                    So with this configuration, Surf and SpringMVC aren't colliding anymore and I can have Surf serve URLs prefixed with /service/* and SpringMVC serve URLs prefixed with /mvc/*.

                    I'm wondering, on certain occassions could we have SpringMVC forward to a Surf webscript with some type of custom ViewResolver? I think you touched on this in your 1st point in your last reply.

                    I ask that last question only because the Java-based webscript doesn't feel very good to me. It feels like we are trying to force the cause to use Java as our controller and what I really didn't care for is how we had to configure/declare this java-based webscript in yet another spring file which has to be buried under org.springframework.extensions.webscripts like so

                    Code:
                    	<!-- id="webscript.<packageId>.<serviceId>.<httpMethod>"  -->
                    	<bean id="webscript.webscripts.ProductDetailsComponent.productdetails.get" 
                             class="com.soundstrue.directweb.surf.controller.ProductDetailsController"
                             parent="webscript">
                               <property name="daoConfig" value="dao-config.xml"/>

                    Comment


                    • #11
                      Just saw your post - looks like we posted about the same time with roughly the same ideas except yours is more complete and works!

                      Are you thinking of forwarding the Spring MVC request to a Surf webscript to populate a portion of the page or a rss feed or something? I think you'd probably want to just go via a URL that Surf services so that you get all of the Surf processing. If you tried to just have a Spring MVC View Resolver go to Surf's view layer direct it would miss out things like the Surf interceptors. One of these populates the context object on which lots of the webscript stuff depends.

                      My View Resolver suggestion was for going the other way - from Surf to a Spring JSP but I'm not sure it would work... especially given the other thread about using JSP.

                      Comment


                      • #12
                        Nice! What are the odds!

                        Correct, I was thinking that after a SpringMVC controller did it's processing we could maybe forward the request to Surf to populate a portion (what we are calling a standard component) of the page. I'm not entirely sure we want to do this or if it even makes sense to.

                        Thanks again for the ideas Chris, you were a tremendous help!

                        Comment


                        • #13
                          No problem, I'm a bit of a Spring Surf fan. Talking of Struts which you mentioned earlier my current customer isn't using Surf but instead Struts 1 with the best bits removed, combined with things like EJB 2

                          Comment


                          • #14
                            Reg Source Code

                            Hi All,

                            Could you please provide me source code which uses spring surf and spring MVC together. As its very helpful to learn.
                            Thank you all,

                            Comment


                            • #15
                              I was using website stage May MVC remote controls with some of my Search websites (which also had Search Webscript remote controls for some of the elements on the page). I can think of a number of guidelines you could go:
                              1. Create a personalized made PageViewResolver training (check the Search resource for the normal one) which ahead to your JSPs. This obviously still has your May MVC sessions being prepared by Search. The training has two techniques - one to choose if it will manage the particular URL and one to come back a Search PageView item. The PageView could then somehow provide the JSPs without too much Search engagement....my understanding all gets a bit imprecise here... so not 100% sure and this would need some testing and might not be the best way etc.
                              2. Individual servlet dispatchers for May MVC and Search if its possible to keep the perspective xml separate which is where I think you began. I don't know why that wasn't functioning but it seems like it should.
                              3. Erm.... there may be a another way of using JSP making which bypasses much of the Search products. I'll have a think when I'm more awaken.

                              Comment

                              Working...
                              X