Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/335.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
Java Spring社交/connect/twitter请求方法';获取';不支持_Java_Spring Mvc_Spring Boot_Spring Social - Fatal编程技术网

Java Spring社交/connect/twitter请求方法';获取';不支持

Java Spring社交/connect/twitter请求方法';获取';不支持,java,spring-mvc,spring-boot,spring-social,Java,Spring Mvc,Spring Boot,Spring Social,下面我将使用spring boot为twitter设置spring social,但当我运行应用程序并重定向到localhost:8080/connect/twitter时,我得到: 出现意外错误(类型=方法不允许,状态=405)。 不支持请求方法“GET” 我知道这与ConnectController的映射有关,我该如何解决这个问题 @Controller public class HelloTwitterController { private final Twitter twitt

下面我将使用spring boot为twitter设置spring social,但当我运行应用程序并重定向到localhost:8080/connect/twitter时,我得到:

出现意外错误(类型=方法不允许,状态=405)。 不支持请求方法“GET”

我知道这与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);
    }
}

代码中没有视图解析器,因此无法呈现视图(返回的字符串)

您必须添加视图解析器(例如thymeleaf、freemarker、jsp)或将这一行放在application.properties中

spring.social.auto_connection_views=true

这将使用默认模板呈现视图。

@Dmitry Zlykh关于缺少的视图解析程序是正确的,但您不需要显式启用它。在构建文件中有一个适当的依赖项就足够了,Boot将自动启用视图解析器。如果使用Thymeleaf,则执行该操作的代码是

对于Gradle项目,请将以下内容放入
build.Gradle
,您应该已经全部设置好了

runtime("org.springframework.boot:spring-boot-starter-thymeleaf")

显示您的控制器类别我刚刚添加了控制器您要点击的URL是什么,控制器顶部没有路径映射?我点击的是localhost:8080,控制器顶部没有路径映射您可以将其作为解决方案发布…;-)把密码打进去?