Hi,
I am a beginner to Spring and newbie to Spring AOP but I am pretty impressed with your work. I am a big fan of spring social especially, among your other offerings.
I tried to migrate the spring social's configuration from java based to XML based and thats where the spring aop and proxy came into picture.
I do understand that java based configuration is powerful than the xml based one but due to seggregation of configuration to xmls, I chose to try it out.
[Note: For me there isnt a usecase which may make me to rethink this descision and go for a hybrid approach at best, partly java based and partly xml based configuration, to get the best of both world.]
While using the xml based configuration, the code compiles fine and deploys (thanks to lazy-init) but when after succesful signin via say facebook, I have put injection for facebook object (property being of type Facebook interface), the object which should have been initialized with necessary authorization for current user and returned. In current scenario proxy to concrete facebook object being returned [Note: I believe the proxied object is actually the subclass of the object being proxied, as I recall from my initial lookup elsewhere in this regard], I get following error:
-----------------------------------------------------
[Stacktrace]
-----------------------------------------------------Code:SEVERE: Servlet.service() for servlet [SpringParentController] in context with path [/SpringFB] threw exception [Request processing failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'facebookHomeController' defined in ServletContext resource [/WEB-INF/application-context-servlet.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type '$Proxy114 implementing java.io.Serializable,org.springframework.aop.scope.ScopedObject,org.springframework.aop.framework.AopInfrastructureBean,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised' to required type 'org.springframework.social.facebook.api.Facebook' for property 'facebook'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [$Proxy114 implementing java.io.Serializable,org.springframework.aop.scope.ScopedObject,org.springframework.aop.framework.AopInfrastructureBean,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [org.springframework.social.facebook.api.Facebook] for property 'facebook': no matching editors or conversion strategy found] with root cause java.lang.IllegalStateException: Cannot convert value of type [$Proxy114 implementing java.io.Serializable,org.springframework.aop.scope.ScopedObject,org.springframework.aop.framework.AopInfrastructureBean,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [org.springframework.social.facebook.api.Facebook] for property 'facebook': no matching editors or conversion strategy found at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:241) at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:470) at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:516) at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:510) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1406) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1365) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1118) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) at org.springframework.beans.factory.support.AbstractBeanFactory$2.getObject(AbstractBeanFactory.java:332) at org.springframework.web.context.request.AbstractRequestAttributesScope.get(AbstractRequestAttributesScope.java:43) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:328) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1093) at org.springframework.web.servlet.handler.AbstractUrlHandlerMapping.lookupHandler(AbstractUrlHandlerMapping.java:152) at org.springframework.web.servlet.handler.AbstractUrlHandlerMapping.getHandlerInternal(AbstractUrlHandlerMapping.java:102) at org.springframework.web.servlet.handler.AbstractHandlerMapping.getHandler(AbstractHandlerMapping.java:288) at org.springframework.web.servlet.DispatcherServlet.getHandler(DispatcherServlet.java:1063) ...
application-context.xml
[Extract]
-----------------------------------------------------------------------Code:<context:component-scan base-package="org.springframework.social.connect.jdbc." scoped-proxy="interfaces"/> <context:component-scan base-package="org.springframework.social.connect.support" scoped-proxy="interfaces"/> <context:component-scan base-package="org.springframework.social.connect.web" scoped-proxy="interfaces"/> <context:component-scan base-package="org.springframework.social.facebook" scoped-proxy="interfaces"/> <context:component-scan base-package="org.springframework.social.facebook.api" scoped-proxy="interfaces"/> ... <bean id="usersConnectionRepository" class="org.springframework.social.connect.jdbc.JdbcUsersConnectionRepository" primary="true" scope="singleton"> <constructor-arg type="javax.sql.DataSource" ref="dataSource"/> <constructor-arg type="org.springframework.social.connect.ConnectionFactoryLocator" ref="connectionFactoryLocator"/> <constructor-arg type="org.springframework.security.crypto.encrypt.TextEncryptor" ref="textEncryptor"/> <property name="connectionSignUp" ref="simpleConnectionSignUp"/> </bean> <bean name="connectionRepository" class="org.springframework.social.connect.ConnectionRepository" factory-bean="usersConnectionRepository" factory-method="createConnectionRepository" scope="request" lazy-init="true"> <constructor-arg value="#{request.userPrincipal.name}"/> <aop:scoped-proxy proxy-target-class="false"/> </bean> <bean id="OA2ConectionClass" class="org.springframework.social.connect.Connection" factory-bean="connectionRepository" factory-method="getPrimaryConnection" scope="request" lazy-init="true"> <constructor-arg type="java.lang.Class" value="org.springframework.social.facebook.api.Facebook"/> <aop:scoped-proxy proxy-target-class="false"/> </bean> <bean id="facebook" class="org.springframework.social.facebook.api.Facebook" factory-bean="OA2ConectionClass" factory-method="getApi" scope="request" lazy-init="true"> <aop:scoped-proxy proxy-target-class="false"/> </bean>
pom.xml
[Extract]
------------------------------------------------------------------------Code:<dependencies> <dependency> <groupId>org.springframework.social</groupId> <artifactId>spring-social-core</artifactId> <version>1.0.2.RELEASE</version> <type>jar</type> <scope>compile</scope> </dependency> <dependency> <groupId>org.springframework.social</groupId> <artifactId>spring-social-web</artifactId> <version>1.0.2.RELEASE</version> <type>jar</type> <scope>compile</scope> </dependency> <dependency> <groupId>org.springframework.social</groupId> <artifactId>spring-social-facebook</artifactId> <version>1.0.1.RELEASE</version> <type>jar</type> <scope>compile</scope> </dependency> <dependency> <groupId>org.springframework.social</groupId> <artifactId>spring-social-facebook-web</artifactId> <version>1.0.1.RELEASE</version> <type>jar</type> <scope>compile</scope> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-crypto</artifactId> <version>3.1.0.RELEASE</version> <type>jar</type> <scope>compile</scope> </dependency> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.2</version> <type>jar</type> <scope>compile</scope> </dependency> ... <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>3.1.1.RELEASE</version> <type>jar</type> <scope>compile</scope> </dependency> <dependency> <groupId>cglib</groupId> <artifactId>cglib-nodep</artifactId> <version>2.2.2</version> <type>jar</type> <scope>compile</scope> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> <version>3.1.1.RELEASE</version> <type>jar</type> <scope>compile</scope> </dependency> ... </dependencies>
One more thing, upon new user being connected and returning user being directly sent to the home area works fine with authentication and database record creation/updation. So getting the facebook object to do operations should not have been a problem.
Please feel free to correct me if I am missing something important or if you can point me to an appropriate resource for resolving this. I have already taken look at the quickstart and showcase samples.
I appreciate all the help I can get in resolving this.
Thanks & regards,
Vinayak


Reply With Quote
