Announcement Announcement Module
No announcement yet.
URL issue when using existing Spring MVC Controller with Grails Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • URL issue when using existing Spring MVC Controller with Grails


    In my Grails application, I added a dependency to "spring-social" project (not the grails plugin but the actual spring-social project developed in Spring MVC). Further, I configured the beans as described in the spring social documentation.

    I did NOT create Grails Controllers and instead I'm using the controllers declared in the spring-social project. However, I created GSP views so the controllers in the spring-social render those views.

    Here is a summary of what I have done:
    1) BuildConfig.groovy

        dependencies {
            def springSocialVersion = "1.0.2.RELEASE"
            def springSocialFacebookVersion = "1.0.1.RELEASE"
            // specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.
            compile "${springSocialVersion}"
            compile "${springSocialVersion}"
            compile "${springSocialFacebookVersion}"
            compile ""
    2) under src/java, created "" that contains bean configurations as described in the spring social documentation and samples

    3) config.groovy, I pointed to the config package so Grails can scan the bean configuration
    // packages to include in Spring bean scanning
    grails.spring.bean.packages = [""]
    I omitted some customization I did such as user domain class and related DAOs, but long story short I got it working with a caveat.

    In the GSP file, I had to add ".dispatch" suffix to the post URL like this
        <form name="fb_signin" id="fb_signin" action="signin/facebook.dispatch" method="POST">
            <input type="hidden" name="scope" value="email,publish_stream,user_photos,offline_access" />
            <button type="submit" class="connectButton">Facebook</button>
    If I omit the ".dispatch" suffix, I get 404 error. I also found that if I omit the suffix in the view but add a URL mapping, it also works:
    I'm not happy with either workaround:
    1) I don't like adding the "dispatch" suffix in view because I don't have to do that when I use Grails Controller. So whoever implements the view now needs to know that the controller is either implemented in Grails or Spring MVC.
    2) I don't like adding the URL Mapping either because I couldn't figure out how to use wildcards so I wouldn't have to add a mapping for every URL combination. Specifically I tried to do something like this with no success
    Otherwise I have to add a mapping for every action that is handled by signin controller that is declared in Spring MVC.

    I'm looking for some guidance and suggestions on either how to better integrate existing Spring MVC controllers into Grails so that I don't have to use the suffix or a convenient way to the URL mapping as I described above.


  • #2
    Hi melicin,

    I appreciated your post, as it gave me a hint of integrating spring-social to grails. However, you wrote "However, I created GSP views so the controllers in the spring-social render those views."

    How did you do that? I was testing a lot of things and the spring social controllers always want to find a JSP, e.g. /WEB-INF/grails-app/viewsconnect/facebookConnect.jsp

    I might have found out, that this is a fallback behaviour, but where did you put your GSPs to get used.

    Sry for warming up that thread.