This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

Can you confirm which version of Spring Social you are working with? I had this exact same problem at one time (about a week ago), but it turned out to be a copy-n-paste error that has since been fixed.

For grins, try removing the Facebook provider and see if the error goes away.

Comment

Another thing that might be going on is that you have a @Configuration-annotated class and then you're (probably...I can't tell for sure here) component-scanning the same package that the class is in from your XML. My guess is that SocialWebConfig is being used twice...once because it is annotated with @Configuration and again due to component-scanning.

If this is the problem (and I can't be certain for lack of visibility into the rest of your code), the fix is to add an exclusion to the <context:component-scan> to not scan for any classes that are annotated with @Configuration. I hope you've also taken care to not have applicationContext.xml anywhere in a page that the import would pick it up again.

Again...this is just a guess because I can't see enough of your project to give a real diagnosis (and again, it'd be handy if this stuff or a smaller facsimile of it were in GitHub so that I can help with the diagnosis).

Comment

I really wish I could share the code. But we are building a Poker app that will be for actual gambling. I am working for a casino/gaming company in Las Vegas and there are so much legal stuff. So much that I don't know if I was even allowed to tell you what I am working on.

I do have a component-scan for loading in the @Configuration. So are you saying that a component scan is already occurring automatically without any config to do so?

I am using the yet to be announced M2 in the SpringSource Milestone repo that you deployed yesterday.

Comment

OK, now I am back to just configuring Spring Social from @Configuration class. I have two component-scans. One for the middle tier, one for the web tier. Both exclude @Configuration. I have only one @Configuration class and I make it a bean by itself in xml with <bean>

I even thought maybe Spring Data Neo4j was doing an internal scan that might have picked it up. But I set a base-package in that config too that would not go into the @Configuration classes package.

I am still getting that duplicate twitter et al.

Now in trying xml, there was a class in Spring Social Security that got me wondering if two locators were being created. The base one with @EnableTwitter and another in Social Security for SocialAuthenticationServiceLocator. When I was doing xml I would get that as a bean not found. But with @Configuration there isn't any place in the samples that define an @Bean for it, but it seems like that is then created automatically, because I would have a different failure if it wasn't.

Comment

OK. I am now back to being able to deploy my application. I still have some errors, but I got past the already registered provider error.

And my last post was correct. If you are going to use the Spring Social Security Filter, you cannot also use the @EnableTwitter like annotations because you will end up with two locators. One that @EnableTwitter creates and a SocialAuthenticationServiceLocator which by the way extends ConnectionFactoryRegistry.

So I removed the @Enable annotations, then for my FactoryRegistry I created an @Bean that returns a SocialAuthenticationServiceLocator. But that caused another error because some beans are looking for a bean named connectionFactoryRegistry. So I just made that the name of my @Bean method ConnectionFactoryRegistry() and now I am deploying.

Now my current error is now very much in the realm of something that I can resolve because it is a NPE in my UserDetailsService.

Of course a big contributor to the Spring Social Security, Yuan was where I found the answer on his post

Comment

Interesting. While what I said above is true, in that I couldn't use the @Enable because it created two ServiceLocators. I just noticed in ProviderConfigurationSupport class that it does check first to see if Spring Social Security is there and if so instantiate a SocialAuthenticationServiceLocator instead of ConnectionFactory.

So maybe there is a way to configure it to make it work, it is just that it is cleaner than it was before, and I think the samples don't reflect the new changes.

That's not what is causing the problem. I do not have an @ComponentScan anywhere. And I only have the one component-scan and it is very filtered already and only finds @Controller classes. Now, in the @Configuration class there is an @Bean for ProviderSignInController, and if you think that would cause two ConnectionFactoryLocator implementations to be created, then that would be the way that would be the cause.

Anyway, as I have said, I have gotten past the error by not using the @EnableTwitter annotations.

As far as my most recent issues, I have found that I was getting the 401 exception because my UserDetailsService throws UserNotFoundException, and Spring Social was only redirecting to your signup page if a BadCredentialsException is thrown. UserNotFoundException extends AuthenticationException, so not in the BadCredentialsException hierarchy.

So for a workaround, in SocialUserDetailsService, when I call my UserDetailsService, I catch UserNotFoundException and throw a new BadCredentialsException, and that is definitely a hack. I mean it is a UserNotFound problem because the user isn't in our database yet for Spring Security.

I don't know if the code that catches BadCredentialsException needs to be changed to catching AuthenticationException, but that might be too broad.

and, I am combining my xml config files for brevity. And I do have two component-scans in xml, one for the middle tier and one for the web tier, but they already had exclusions for @Configuration. And therefore had to use <bean> tag to include the one @Configuration class.

Comment

But I also do want to make one point. We should never have to <exclude-filter> @Configuration everywhere, that right now is a hack too. When you do component-scan tags, it should more be based on base-package and sometimes the filter on other Stereotypes, like keeping @Controllers from your middle tier etc.

By virtue of the fact that it's annotated with @Component, it *will* be picked up by component-scanning. That's usually a good thing. However, there are times when it can be a hassle...especially if within your @Configuration class you have a @ComponentScan that scans the base package (and recursively whatever package the @Configuration class is found in).

(I'm not sure if any of that explanation helps you or not, but I thought I'd offer it anyway just to be clear on the fact that @Configuration classes are prone to be component-scanned.)

So, I'm a bit lost on where you stand now. Is it working or not? I see that you've commented out both @EnableTwitter and @EnableFacebook, so my guess is that it's not quite working yet.