java - Integrate Spring Socials (Facebook) with Spring MVC XML Based -
i have working spring mvc webapp , xml based have use same procedures , not "pure java configs".
i'm trying integrate facebook sign in app , have tried follow many tutorials couldn't manage make them work.
here 1 of tries: (https://spring.io/guides/gs/accessing-facebook/)
edit:
my xml this:
<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:facebook="http://www.springframework.org/schema/social/facebook" xmlns:twitter="http://www.springframework.org/schema/social/twitter" xmlns:social="http://www.springframework.org/schema/social" xmlns:linkedin="http://www.springframework.org/schema/social/linkedin" xmlns:c="http://www.springframework.org/schema/c" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemalocation="http://www.springframework.org/schema/social/facebook http://www.springframework.org/schema/social/spring-social-facebook.xsd http://www.springframework.org/schema/social/linkedin http://www.springframework.org/schema/social/spring-social-linkedin.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/social/twitter http://www.springframework.org/schema/social/spring-social-twitter.xsd http://www.springframework.org/schema/social http://www.springframework.org/schema/social/spring-social.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd"> <bean id="connectionfactorylocator" class="org.springframework.social.connect.support.connectionfactoryregistry"> <property name="connectionfactories"> <list> <bean class="org.springframework.social.facebook.connect.facebookconnectionfactory"> <constructor-arg value="${facebook.clientid}" /> <constructor-arg value="${facebook.clientsecret}" /> </bean> </list> </property> </bean> <bean id="usersconnectionrepository" class="org.springframework.social.connect.jdbc.jdbcusersconnectionrepository"> <constructor-arg ref="datasource" /> <constructor-arg ref="connectionfactorylocator" /> <constructor-arg ref="textencryptor" /> </bean> <bean id="connectionrepository" factory-method="createconnectionrepository" factory-bean="usersconnectionrepository" scope="request"> <constructor-arg value="#{request.userprincipal.name}" /> <aop:scoped-proxy proxy-target-class="false" /> </bean> <bean class="org.springframework.social.connect.web.connectcontroller"> <!-- relies on by-type autowiring constructor-args --> </bean> <bean class="org.springframework.social.connect.web.connectcontroller"> <!-- relies on by-type autowiring constructor-args --> <property name="applicationurl" value="${application.url}" /> </bean> <facebook:config app-id="962223610477458" app-secret="b7dfec28b08ac4e8c2a09cbac4662c15" app-namespace="setelog_selectandwin" /> </beans>
homecontroller:
@controller public class homecontroller {
private static final logger logger = loggerfactory.getlogger(homecontroller.class); private facebook facebook; private connectionrepository connectionrepository; @inject public homecontroller(facebook facebook, connectionrepository connectionrepository) { this.facebook = facebook; this.connectionrepository = connectionrepository; } /** * selects home view render returning name. */ @requestmapping(value = "/", method = requestmethod.get) public string home(locale locale, model model) { if (connectionrepository.findprimaryconnection(facebook.class) == null) { return "redirect:/connect/facebook"; } model.addattribute("facebookprofile", facebook.useroperations().getuserprofile()); pagedlist<post> feed = facebook.feedoperations().getfeed(); model.addattribute("feed", feed); return "facebook/hello"; }
}
now error caused by: org.springframework.beans.factory.nosuchbeandefinitionexception: no bean named 'scopedtarget.connectionfactorylocator' defined
if remove th facebook:config tag gives me following error because there no such bean:
caused by: org.springframework.beans.factory.nosuchbeandefinitionexception: no matching bean of type [org.springframework.social.facebook.api.facebook] found dependency: expected @ least 1 bean
any suggestions?
you need not add spring's facebook interface class in xml. instead create facebookconnectionfactory using facebook client id , secret using xml or java code.
@configuration public class socialconfig implements socialconfigurer { @override public void addconnectionfactories(connectionfactoryconfigurer cfconfig, environment env) { cfconfig.addconnectionfactory(new facebookconnectionfactory( env.getproperty("facebook.clientid"), env.getproperty("facebook.clientsecret"))); } ... }
or
using spring social facebook’s xml configuration namespace:
<facebook:config app-id="${facebook.clientid}" app-secret="${facebook.clientsecret}" app-namespace="socialshowcase" />
refer : spring social facebook reference
Comments
Post a Comment