Java springbootbean返回null
我正在尝试将我的Spring Boot应用程序连接到Facebook。 我正在关注与facebook的春季社交整合 build.gradle包括以下行:Java springbootbean返回null,java,spring,facebook,spring-boot,spring-social,Java,Spring,Facebook,Spring Boot,Spring Social,我正在尝试将我的Spring Boot应用程序连接到Facebook。 我正在关注与facebook的春季社交整合 build.gradle包括以下行: 编译“org.springframework.social:springsocialfacebook” application.properties: spring.social.facebook.appId=myappid spring.social.facebook.appSecret=我的应用程序密钥 我使用的不是控制器,而是RestCo
编译“org.springframework.social:springsocialfacebook”
application.properties:spring.social.facebook.appId=
myappid
spring.social.facebook.appSecret=
我的应用程序密钥
我使用的不是控制器,而是RestController,因为这是一个单页应用程序
我的RestController看起来像这样
@RestController
@RequestMapping(value = "/users", produces = MediaType.APPLICATION_JSON_VALUE)
public class UserResource extends CrudResource<User, UserService> {
@Autowired
UserService userService;
private Facebook facebook;
@Inject
public UserResource(Facebook facebook) {
this.facebook = facebook;
}
@RequestMapping(value = "/fb", method = RequestMethod.GET)
public String helloFacebook(Model model) {
if (!facebook.isAuthorized()) {
return "redirect:/connect/facebook";
}
model.addAttribute(facebook.userOperations().getUserProfile());
PagedList<Post> homeFeed = facebook.feedOperations().getHomeFeed();
model.addAttribute("feed", homeFeed);
return "hello";
}
//...other not important code here
}
上出现空指针异常!isAuthorized()
,在调试模式下,facebook对象在这一行时为空。
{code}编译'org.springframework.social:springsocialfacebook'{code}
告诉gradle这是一个编译时依赖项。即使在运行时,您也可能需要在类路径上使用此人工制品
因此,它可能应该被更改,以便您在cp运行时获得它。同样的情况也发生在我身上。对于SpringBootMaven插件,我不得不从1.2.7降级到1.2.3
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<!--<version>1.2.7.RELEASE</version>-->
<!-- downgraded because of bug in HelloControler
facebook.isAuthorized() some null/proxy bug-->
<version>1.2.3.RELEASE</version>
</parent>
渐变设置很好,库存在于项目中。另外,这一行就像spring示例(在依赖项中)一样,我认为这就解决了这个问题。。同时,我也去了。很好用。
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<!--<version>1.2.7.RELEASE</version>-->
<!-- downgraded because of bug in HelloControler
facebook.isAuthorized() some null/proxy bug-->
<version>1.2.3.RELEASE</version>
</parent>
dependencies {
classpath("org.springframework.boot:
spring-boot-gradle-plugin:1.2.3.RELEASE")
}