Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何通过XML配置Spring Social_Spring_Aop_Spring Aop_Spring Social_Xml Configuration - Fatal编程技术网

如何通过XML配置Spring Social

如何通过XML配置Spring Social,spring,aop,spring-aop,spring-social,xml-configuration,Spring,Aop,Spring Aop,Spring Social,Xml Configuration,我花了几个小时尝试使用XML配置方法将Twitter集成到SpringSocial中。我在web(和stackoverflow)上找到的所有示例都始终使用@Config方法,如 无论出于何种原因,获取twitter API实例的bean定义都会引发AOP异常: Caused by: java.lang.IllegalStateException: Cannot create scoped proxy for bean 'scopedTarget.twitter': Target type cou

我花了几个小时尝试使用XML配置方法将Twitter集成到SpringSocial中。我在web(和stackoverflow)上找到的所有示例都始终使用
@Config
方法,如

无论出于何种原因,获取twitter API实例的bean定义都会引发AOP异常:

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.
以下是我拥有的完整配置文件:

    <?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>

任何帮助/指点都将不胜感激

我有一个用于Spring社交Facebook集成的配置。(我有twitter配置,但我还没有测试其中的twitter部分)



它足够小,可以阅读,并且与spring security的集成有更多的关系。我希望这在某种程度上有所帮助。

我有一个适用于tomcat7的xml spring mvc/spring社交配置

这个问题很久以前就发布了,但是我的帖子中的配置可能会为一些人节省一些时间。我花了相当长的时间来设置XML配置和最新的Spring4.2.4MVC,包括 spring社交(1.1.4)和spring社交推特(1.1.2)推特连接。
我在这里编写版本,因为spring版本之间有很多不同之处

嗯,正如我说的。。。官方文件不包括我的问题所涉及的缺失部分。spring social showcase应用程序使用基于@Config注释的配置。您的示例也没有包含缺少的部分“twitter”的bean定义,但是感谢您的尝试!干杯
@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));
    }
}
<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" />