I'm still learning spring and currently I'm trying to create webapplication and RESTful API at the same server. It was easy until I tried to add OAuth2 authorizaton to be able to consume that API in Android application. I have a problem because I don't completely understand what is happening under the hood of spring.
I want achieve something like this:
Is it even possible? Can you provide an example code or just the way I should do it?
Well, Spring Boot has plenty of documentation.
I'd recommend the Spring Boot manual
As for what you want, yes, it's possible. See this demo which has OAuth, REST API and normal HTML, CSS, JS files all in one. Also, this demo is based on spring-boot, so what more do you want :)
Again, the demo url: https://github.com/szerhusenBC/jwt-spring-security-demo/
As I said above, it's possible. Not recommended, but possible. It would be recommended to split them, for a better separation of concerns. Also for performance reasons: Apache for instance can serve static files much faster than SpringBoot/Tomcat can. Of course you can start this way and do it later. Enjoy.