2012-10-02 11 views
8

के माध्यम से स्प्रिंग सोशल को कॉन्फ़िगर कैसे करें मैं XML कॉन्फ़िगरेशन दृष्टिकोण का उपयोग कर स्प्रिंग सोशल के साथ काम करने के लिए ट्विटर एकीकरण प्राप्त करने के कुछ घंटों खर्च करता हूं।एक्सएमएल

: सभी उदाहरण मैं वेब पर मिल सकता है (और stackoverflow पर) हमेशा चहचहाना एपीआई के एक उदाहरण के रूप में प्राप्त करने के लिए samples

जो भी कारण सेम परिभाषा में दिखाया गया @Config दृष्टिकोण का उपयोग एक AOP अपवाद फेंकता

<?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:jaxrs="http://cxf.apache.org/jaxrs" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:util="http://www.springframework.org/schema/util" 
    xmlns:cxf="http://cxf.apache.org/core" 
    xmlns:aop="http://www.springframework.org/schema/aop" 
    xmlns:jee="http://www.springframework.org/schema/jee" 
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xmlns:jdbc="http://www.springframework.org/schema/jdbc" 
    xsi:schemaLocation=" 
     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd 
     http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd 
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd 
     http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd 
     http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd 
     http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd 
     http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd 
     http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd 
     http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd"> 

    <import resource="classpath:META-INF/cxf/cxf.xml" /> 
    <import resource="classpath:META-INF/cxf/cxf-servlet.xml" /> 

    <jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/DefaultDB" /> 

    <!-- initialize DB required to store user auth tokens --> 
    <jdbc:initialize-database data-source="dataSource" ignore-failures="ALL"> 
     <jdbc:script location="classpath:/org/springframework/social/connect/jdbc/JdbcUsersConnectionRepository.sql"/> 
    </jdbc:initialize-database> 

    <bean id="connectionFactoryLocator" 
     class="org.springframework.social.connect.support.ConnectionFactoryRegistry"> 
     <property name="connectionFactories"> 
      <list> 
       <ref bean="twitterConnectFactory" /> 
      </list> 
     </property> 
    </bean> 

    <bean id="twitterConnectFactory" class="org.springframework.social.twitter.connect.TwitterConnectionFactory"> 
     <constructor-arg value="xyz" /> 
     <constructor-arg value="xzy" /> 
    </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 id="twitter" factory-method="findPrimaryConnection" 
     factory-bean="connectionRepository" scope="request" depends-on="connectionRepository"> 
     <constructor-arg value="org.springframework.social.twitter.api.Twitter" /> 
     <aop:scoped-proxy proxy-target-class="false" /> 
    </bean> 


    <bean id="textEncryptor" class="org.springframework.security.crypto.encrypt.Encryptors" 
     factory-method="noOpText" /> 

    <bean id="connectController" class="org.springframework.social.connect.web.ConnectController"> 
     <constructor-arg ref="connectionFactoryLocator"/> 
     <constructor-arg ref="connectionRepository"/> 
     <property name="applicationUrl" value="https://socialscn.int.netweaver.ondemand.com/socialspringdemo" /> 
    </bean> 

    <bean id="signInAdapter" class="com.sap.netweaver.cloud.demo.social.SimpleSignInAdapter" /> 

</beans> 

मुझे क्या पहेली है कि connectionRepository इन्स्टेन्शियशन पूरी तरह से ठीक काम करता है (मैं टिप्पणी की-आउट चहचहाना सेम और कोड का परीक्षण!):

Caused by: java.lang.IllegalStateException: Cannot create scoped proxy for bean 'scopedTarget.twitter': Target type could not be determined at the time of proxy creation. 

यहाँ पूरा कॉन्फ़िग फ़ाइल मेरे पास है?!? यह एक ही विशेषताएं का उपयोग करता है: अनुरोध स्कोप और इंटरफ़ेस एओपी प्रॉक्सी और काम करता है, लेकिन twitter बीन तत्काल विफल रहता है?!

इस प्रकार वसंत सामाजिक config कोड लग रहा है (मैं नहीं किसी भी मतभेद, कर सकते हैं जैसा कि आप देख सकते हैं?):

@Configuration 
public class SocialConfig { 

    @Inject 
    private Environment environment; 

    @Inject 
    private DataSource dataSource; 

    @Bean 
    @Scope(value="singleton", proxyMode=ScopedProxyMode.INTERFACES) 
    public ConnectionFactoryLocator connectionFactoryLocator() { 
     ConnectionFactoryRegistry registry = new ConnectionFactoryRegistry(); 
     registry.addConnectionFactory(new TwitterConnectionFactory(environment.getProperty("twitter.consumerKey"), 
       environment.getProperty("twitter.consumerSecret"))); 
     return registry; 
    } 

    @Bean 
    @Scope(value="singleton", proxyMode=ScopedProxyMode.INTERFACES) 
    public UsersConnectionRepository usersConnectionRepository() { 
     return new JdbcUsersConnectionRepository(dataSource, connectionFactoryLocator(), Encryptors.noOpText()); 
    } 

    @Bean 
    @Scope(value="request", proxyMode=ScopedProxyMode.INTERFACES) 
    public ConnectionRepository connectionRepository() { 
     Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); 
     if (authentication == null) { 
      throw new IllegalStateException("Unable to get a ConnectionRepository: no user signed in"); 
     } 
     return usersConnectionRepository().createConnectionRepository(authentication.getName()); 
    } 

    @Bean 
    @Scope(value="request", proxyMode=ScopedProxyMode.INTERFACES) 
    public Twitter twitter() { 
     Connection<Twitter> twitter = connectionRepository().findPrimaryConnection(Twitter.class); 
     return twitter != null ? twitter.getApi() : new TwitterTemplate(); 
    } 

    @Bean 
    public ConnectController connectController() { 
     ConnectController connectController = new ConnectController(connectionFactoryLocator(), connectionRepository()); 
     connectController.addInterceptor(new PostToWallAfterConnectInterceptor()); 
     connectController.addInterceptor(new TweetAfterConnectInterceptor()); 
     return connectController; 
    } 

    @Bean 
    public ProviderSignInController providerSignInController(RequestCache requestCache) { 
     return new ProviderSignInController(connectionFactoryLocator(), usersConnectionRepository(), new SimpleSignInAdapter(requestCache)); 
    } 
} 

किसी भी मदद/संकेत की सराहना की जाएगी !!!

उत्तर

5

मेरे पास एक कॉन्फ़िगरेशन है जो स्प्रिंग सोशल फेसबुक एकीकरण के लिए काम करता है। (मैं इसे में चहचहाना विन्यास है, लेकिन मैं इसे में चहचहाना हिस्सा परीक्षण नहीं किया)

<bean class="org.springframework.social.connect.web.ProviderSignInController"> 
<!-- relies on by-type autowiring for the constructor-args -->  
<constructor-arg ref="signInAdapter" /> 
</bean> 

<bean id="connectionFactoryLocator" 
    class="org.springframework.social.connect.support.ConnectionFactoryRegistry"> 
<property name="connectionFactories"> 
    <list> 
     <bean class="org.springframework.social.twitter.connect.TwitterConnectionFactory"> 
      <constructor-arg value="${twitter.consumerKey}" /> 
      <constructor-arg value="${twitter.consumerSecret}" />    
     </bean> 
     <bean class="org.springframework.social.facebook.connect.FacebookConnectionFactory"> 
      <constructor-arg value="${facebook.clientId}" /> 
      <constructor-arg value="${facebook.clientSecret}" />     
     </bean> 
    </list> 
</property> 
</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 id="signInAdapter" class="com.test.social.SimpleSignInAdapter"/> 

<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="textEncryptor" class="org.springframework.security.crypto.encrypt.Encryptors" 
     factory-method="noOpText" /> 

मैं मुख्य रूप से documentation जो काफी छोटा पढ़ने के लिए है और एक tutorial जो के साथ एकीकरण के साथ क्या करना अधिक था कहा जाता है वसंत सुरक्षा। मुझे उम्मीद है कि यह किसी भी तरह से मदद करता है।

+0

ठीक है, जैसा कि मैंने कहा था ... आधिकारिक दस्तावेज में मेरे प्रश्न से संबंधित गुम भाग शामिल नहीं है। वसंत-सामाजिक-शोकेस ऐप @ कॉनफिग एनोटेशन-आधारित कॉन्फ़िगरेशन का उपयोग करता है। आपके उदाहरण में गायब भाग - "ट्विटर" की बीन परिभाषा शामिल नहीं है - लेकिन फिर भी कोशिश करने के लिए धन्यवाद! चीयर्स! –

0

मेरे पास this question I posted में tomcat7 के लिए एक काम कर रहे xml वसंत-एमवीसी/स्प्रिंग-सोशल कॉन्फ़िगरेशन है।

यह प्रश्न बहुत समय पहले पोस्ट किया गया था, लेकिन शायद मेरे पोस्ट में कॉन्फ़िगरेशन कुछ लोगों को कुछ समय बचाएगा। मुझे एक्सएमएल कॉन्फ़िगरेशन और नवीनतम वसंत 4.2.4 एमवीसी के साथ स्थापित करने में काफी समय लगा, जिसमें वसंत-सामाजिक (1.1.4) और वसंत-सामाजिक-ट्विटर (1.1.2) ट्विटर कनेक्शन शामिल है। मैं यहां संस्करण लिखता हूं, क्योंकि वसंत संस्करणों के बीच कुछ चीजें अलग-अलग हैं।