2
votes

I'm following http://spring.io/guides/gs/accessing-twitter/ to setup spring social for twitter with Spring boot but when I run the application and redirected to localhost:8080/connect/twitter I'm getting:

There was an unexpected error (type=Method Not Allowed, status=405). Request method 'GET' not supported

I know this have something to do with with the mapping of ConnectController how do I really fix this?

@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);
    }
}
2
show your Controller classJuned Ahsan
I just added the Controlleruser2054833
what is the URL you are hitting and is there no path mapping on top of your controller?Juned Ahsan
I'm hitting localhost:8080 and there is no path mapping on top of the controlleruser2054833
Can you post it as a solution...;-) Slap the code in there?Marco Schoolenberg

2 Answers

1
votes

There is no view resolver in your code so the views (returned strings) cannot be rendered.

You have to add your view resolver (e.g. thymeleaf, freemarker, jsp) or put this line in application.properties

spring.social.auto_connection_views=true

This will render your views using default templates.

0
votes

@Dmitry Zlykh is right about the missing view resolver, but you don't need to enable it explicitly. Having an appropriate dependency in your build file is good enough, Boot will automatically enable the view resolver. If using Thymeleaf, the code that does that is ThymeleafAutoConfiguration.

For a Gradle project, put the following in the build.gradle, and you should be all set.

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