我正在关注 http://spring.io/guides/gs/accessing-twitter/使用 Spring Boot 为 twitter 设置 spring social 但是当我运行应用程序并重定向到 localhost:8080/connect/twitter 我得到:
There was an unexpected error (type=Method Not Allowed, status=405). Request method 'GET' not supported
我知道这与 ConnectController 的映射有关,我该如何真正解决这个问题?
@Controller
public class HelloTwitterController {
private final Twitter twitter;
private final ConnectionRepository connectionRepo;
@Inject
public MessoTwitterController(Twitter twitter, ConnectionRepository connectionRepo) {
this.twitter = twitter;
this.connectionRepo = connectionRepo;
}
@RequestMapping(value ="/", method = RequestMethod.GET)
public String welcomeTwitter (Model model) {
if (connectionRepo.findPrimaryConnection(Twitter.class) == null)
return "redirect:/connect/twitter";
model.addAttribute(twitter.userOperations().getUserProfile());
model.addAttribute("friends", twitter.friendOperations().getFriends());
return "welcomeTwitter";
}
}
@SpringBootApplication
@EnableAutoConfiguration
@ComponentScan("com.mypackage")
public class MyApplication {
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
}
最佳答案
您的代码中没有 View 解析器,因此无法呈现 View (返回的字符串)。
您必须添加您的 View 解析器(例如 thymeleaf、freemarker、jsp)或将此行放入 application.properties
spring.social.auto_connection_views=true
这将使用默认模板呈现您的 View 。
关于java - 不支持 Spring Social/connect/twitter 请求方法 'GET',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31396544/