- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在使用 Spring Social 连接到 Twitter。连接部分工作正常,但是当我尝试获取好友列表时,出现以下错误:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.springframework.social.twitter.api.Twitter] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
我的 Controller 类:
@Controller
@RequestMapping("/social")
public class SocialController {
private final Twitter twitter;
@Inject
public SocialController(Twitter twitter) {
this.twitter = twitter;
}
@RequestMapping(value="/twitter/friends", method=RequestMethod.GET)
public String friends(Model model) {
model.addAttribute("profiles", twitter.friendOperations().getFriends());
return "twitter/friends";
}
}
我的 XML 配置如下:(只显示相关部分)
<!-- Spring Social -->
<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="textEncryptor" class="org.springframework.security.crypto.encrypt.Encryptors"
factory-method="noOpText" />
<bean id="usersConnectionRepository"
class="org.springframework.social.connect.jdbc.JdbcUsersConnectionRepository">
<constructor-arg ref="jpaDataSource" />
<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 for the constructor-args -->
<property name="applicationUrl" value="${application.url}" />
</bean>
<!-- Spring Social -->
请指导。我将非常感激。
我想我忘了补充
@Bean
@Scope(value="request", proxyMode=ScopedProxyMode.INTERFACES)
public Twitter twitter() {
Connection<Twitter> twitter = connectionRepository().findPrimaryConnection(Twitter.class);
return twitter != null ? twitter.getApi() : new TwitterTemplate();
}
到 XML 文件。知道它将如何在 XML 上下文中表示。我是基于注释的配置的新手,因此使用基于 xml 的配置。请帮忙。
我找到了解决方法。决定同时使用基于注释的配置和基于 XML 的配置。只需添加我为每个人所做的事情:
我添加了一个配置:
public class SocialApiConfig {
@Bean
@Scope(value="request", proxyMode=ScopedProxyMode.INTERFACES)
public Facebook facebook(ConnectionRepository connectionRepository) {
Connection<Facebook> facebook = connectionRepository.findPrimaryConnection(Facebook.class);
return facebook != null ? facebook.getApi() : new FacebookTemplate();
}
@Bean
@Scope(value="request", proxyMode=ScopedProxyMode.INTERFACES)
public Twitter twitter(ConnectionRepository connectionRepository) {
Connection<Twitter> twitter = connectionRepository.findPrimaryConnection(Twitter.class);
return twitter != null ? twitter.getApi() : new TwitterTemplate();
}
}
然后将其包含在我基于 XML 的配置中
<bean class="com.joinups.config.SocialApiConfig" />
感谢大家指导我得到正确答案!多谢。你们摇滚!
最佳答案
您似乎没有声明 Twitter
类型的 bean .
来自 spring documentation我可以看到你需要实例化 Twitter
以某种方式。
尝试声明一个 bean <bean id="twitter" factory-bean="twitterConnectionFactory" />
使用实例化 TwitterTemplate
所需的正确参数对象
这里是通过xml的配置:
<bean id="twitter" factory-method="findPrimaryConnection"
factory-bean="connectionRepository" scope="request" depends-on="connectionRepository">
<constructor-arg value="org.springframework.social.twitter.api.Twitter" />
</bean>
关于java - 找不到类型为 [org.springframework.social.twitter.api.Twitter] 的匹配 bean 以获取依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13089657/
例如,我有一个父类Author: class Author { String name static hasMany = [ fiction: Book,
代码如下: dojo.query(subNav.navClass).forEach(function(node, index, arr){ if(dojo.style(node, 'd
我有一个带有 Id 和姓名的学生表和一个带有 Id 和 friend Id 的 Friends 表。我想加入这两个表并找到学生的 friend 。 例如,Ashley 的 friend 是 Saman
我通过互联网浏览,但仍未找到问题的答案。应该很容易: class Parent { String name Child child } 当我有一个 child 对象时,如何获得它的 paren
我正在尝试创建一个以 Firebase 作为我的后端的社交应用。现在我正面临如何(在哪里?)找到 friend 功能的问题。 我有每个用户的邮件地址。 我可以访问用户的电话也预订。 在传统的后端中,我
我主要想澄清以下几点: 1。有人告诉我,在 iOS 5 及以下版本中,如果您使用 Game Center 设置多人游戏,则“查找 Facebook 好友”(如与好友争夺战)的功能不是内置的,因此您需要
关于redis docker镜像ENTRYPOINT脚本 docker-entrypoint.sh : #!/bin/sh set -e # first arg is `-f` or `--some-
我是一名优秀的程序员,十分优秀!