PDA

View Full Version : Trying to integrate spring social into an existing large application. Issues ....



rickcr
Sep 21st, 2011, 09:45 PM
I don't believe this is a spring social problem per se, but considering I'm trying to integrate spring-social code into an existing application, I'm going to try to articulate the situation since I'm going crazy here and I'm sure the solution has to be simple.

I've upgraded all of our existing application's spring jars to spring 3.0.6 and the existing application works as expected (had some errors on start-up when I tried to use 3.1-M2) This an older app that has grown over time that I inherited. I'm still consider myself a spring rookie, and the majority of web mvc controllers are mapped to requests via BeanNameUrlHandlerMapping: eg <bean name="/foo/bar.do" class="SomeController>

Up front, the main issue I'm having is getting the spring social controllers/beans to recognized. The main dispatch servlet does not map to the path "/", but instead maps to various extensions (eg *.sdo, etc.) I did add a mapping with /social/* and I modified the signin to facebook form post url to /social/signin/facebook, yet this url is never recognized since I can't seem to get the core spring social beans/controller recognized. I did add my own test controller in my own package following all the annotation standards and I can reach the controller just fine as long as I add a context:component-scan to pick up my package, so there has to be something simple I'm doing wrong in regard to not getting the spring social controllers picked up.

I tried my best to follow along with the samples 3.0.X quickstart and I have a root-context defined and it calls a SocialConfig class as well. (I added some logging to my SocialConfig beans and I'll see them fired on startup so I know the root-context is firing and calling SocialConfig.)

I was sure to add <context:annotation-config /> to my root-context as well, and in my spring-servlet.xml I have <mvc:annotation-driven /> defined.

I noticed in the 3.0.x quickstart there is no component-scan used for the base spring social packages so obviously they are getting picked up somewhow in that sample app so I wouldn't think I'd need to add a component-scan for them either? Yet, I did try to add a component-scan to org.springframework.social, but when I do, I get all kinds errors as if nothing in my SocialConfig was initialized first and the core spring social classes start complaining about things being null (such as ProviderController not being intialized with a SignInAdapter - which it is in the SpringSocicalConfig.)

I'm really struggling as to what I need to do to get this all working within the existing architecture. I feel like I'm close but been wrestling with this for way too long now:(

Are there some other things that jump out to any of you that I could try?

(I know I need to manually set some other things since I'm not using / for my main dispatch servlet path but that's described pretty well in this other post http://forum.springsource.org/showthread.php?114878-Change-DispatcherServlet-map-not-to-be-the-root-of-the-app-in-social-samples - I'm not even getting that far though.)

habuma
Sep 22nd, 2011, 12:39 AM
I'm unclear as to what you mean by "getting the spring social controllers/beans to [be] recognized". Are you thinking that the beans are never actually created? Or they may be created, but they're not responding to the URL pattern you think that they should be responding to (e.g., "/social/connect/facebook" or "/social/signin/facebook"? More specifically what happens when you try to go to /social/signin/facebook?

The 3.0.x quickstart doesn't use component scanning for the Spring Social controllers (I assume that's what you're referring to), because it *does* explicitly wire ProviderSignInController from /WEB-INF/spring/appServlet/controllers.xml. Is that what you were looking for?

If there's any more specifics on what you're experiencing, it would be helpful in figuring out what's going on.

rickcr
Sep 22nd, 2011, 10:50 AM
The 3.0.x quickstart doesn't use component scanning for the Spring Social controllers (I assume that's what you're referring to), because it *does* explicitly wire ProviderSignInController from /WEB-INF/spring/appServlet/controllers.xml. Is that what you were looking for?

Thanks! That was the key. What I had done was kept the bean definition for the ProviderSignInController in the SocialConfig java class.

When I mention "getting the spring social controllers/beans to [be] recognized" - I wasn't actually sure if it was a) the beans not being created or b) they were not responding to the URL pattern. When I did attempt to submit the form to /social/signin/facebook I would get "No mapping found for HTTP request with URI [/social/spring/facebook] in DispatcherServlet"

Out of curiosity, if I did want to use the ProviderSignInController defined in the SpringSocial class, I take it I would need to use component-scan for even the core spring social classes (component-scan="org.springframework.social") ? The issue is when I did try this I ran into issues with things not being initialized. It's not too big a of a deal since I'm fine using the xml approach to defining the ProviderSignInController and any of my own spring social controllers that I'll need to define (signin, et.)

Thanks again you helped a lot!