Announcement Announcement Module
No announcement yet.
Spring Social M3: Issue with Scoped-Proxy Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Social M3: Issue with Scoped-Proxy

    I'm developing a sample application that will post feeds to Facebook periodically using Spring's Task Scheduler. I downloaded the latest spring-social-showcase project and extracted the relevant parts for my needs. I also setup a login mechanism using Spring Security 3.1 RC1's in-memory user-service.

    I prefer to work via XML configuration than a Java-based configuration. In order for my application to access the currently authenticated user, I have to follow the following:

    <bean id="connectionRepository" factory-method="createConnectionRepository" factory-bean="usersConnectionRepository" scope="request">
        <constructor-arg value="#{}" />
    The sample spring-social-showcase project uses a Java-based configuration, which is good IF there was also an XML-based configuration demo. Since most Spring users are used to XML-based, I just think that it's best that we include both options in the project. That's my first recommendation.

    However, my real issue is when using the Expression Language "#{}". I have to setup my bean to use a "scope="request" which is understandable. However when I run my application, I get the following error:

    java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? ...
    I'm aware of adding the <aop:scoped-proxy> but I'm wondering why it's never used or mentioned in the documentation (See If it's not used, then it means it's not needed? But my application will not run without it.

    So I added <aop:scoped-proxy>.

    I now have the following:
    <bean id="connectionRepository" factory-method="createConnectionRepository" 
    			factory-bean="usersConnectionRepository" scope="request">
    	    <constructor-arg value="#{}" />
    	    <aop:scoped-proxy />
    I'm able to login and get authenticated via Spring Security. However this still fails when I try to login to Facebook. Here's the simplified stacktrace:

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.connectionRepository'
    org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class]: Common causes of this problem include using a final class or a non-visible class;
    java.lang.IllegalArgumentException: Superclass has no null constructors but no arguments were given
    I have CGLIB on my classpath. I use Maven. To resolve the issue, I had to modify the aop-proxy element with:

    <aop:scoped-proxy proxy-target-class="false"/>
    Then my application works as expected. I understand what proxy-target-class="false" does. It's clearly stated in the docs.

    I'm using the latest jars for Spring Social, Spring Security, and Spring Core:

    Here's a snippet of my Maven properties section:
    I'm wondering why I need to go such process when the documentation (Spring Social) isn't even using such? I might be missing a simple solution here? Thanks a lot

  • #2
    We've recently updated the "spring-social-extending-existing-api" project in spring-social-samples to show XML-based config as an alternative to the Java @Configuration shown in spring-social-showcase.

    Scoped proxies will not be required as long as you inject a Provider<ConnectionRepository> instead of the ConnectionRepository itself, where the JSR 330 Provider will make a lookup for the request-scoped bean when provider.get() is called. This is generally what I'd recommend, and is shown in the samples. If you do use a scoped-proxy, which would allow direct injection of a ConnectionRepository instance, yes, it should be an interface-based JDK dynamic proxy for the ConnectionRepository interface, and not a CGLIB one against the target class implementation. (I honestly still prefer injecting Provider<ConnectionRepository> for clarity that this is a request-scope object that needs to be fetched).

    We should definitely update the documentation to clarify things in this area. Would you mind submitting a JIRA for this?

    Last edited by Keith Donald; May 1st, 2011, 01:52 PM.


    • #3
      Keith, thanks for the info. I will certainly file a JIRA regarding this. I will do it later tonight because I have to post another important issue.

      You're right. The spring-social-showcase project is indeed using @Inject. I use @Resource in my projects. I think the documentation needs to clarify the ramifications of using @Inject, @Autowired, or @Resource. I'll note that in the JIRA later.


      • #4
        Keith, I have filed a JIRA at

        I hope the title is descriptive and accurate enough: Documentation for ConnectionRepository injection should be clarified when using scoped proxies and Provider