Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
118 views
in Technique[技术] by (71.8m points)

java - creating spring rest services without using spring boot

I've followed the Getting Started tutorial on spring.io for building REEST services https://spring.io/guides/gs/rest-service/. The problem is that this tutorial only explain how to produce a standalone running jar with tomcat embedded using spring boot.

Is there a way to create a project from scratch to produce a war to deploy for instance on an already existing tomcat instance?

PS: I had found a previous thread Spring RESTful Service as a WAR instead of JAR in Tomcat on stackoverflow concerning the very same issue. The problem is that the accepted answers and suggestions doesn't exactly solve my problem, since I'm not looking for ways to modify the standalone-app spring boot project so that it works on an external tomcat container, but would like to find a 'cleaner' solution not involving spring boot at all. (I'm not exactly sure how to behave here, being still quite new at stackoverflow. I hope that opening a new question is the correct procedure).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You don't need Spring Boot to create a rest controller.

Please follow the spring framework documentation on how to setup MVC https://docs.spring.io/spring/docs/current/spring-framework-reference/web.html#spring-web

The MVC setup (the DispatcherServlet) depends on your spring version, you can either use xml or you can setup programmatically: https://docs.spring.io/spring/docs/current/spring-framework-reference/web.html#mvc-servlet

Once this is setup, you can add a rest controller to your application. Note that a rest controller (the @RestController annotation) is a stereotype annotation that combines @ResponseBody and @Controller, in other words the Controller returns an object in the response body instead of returning a view.

This is a perfect example explaining what I said above: http://www.programming-free.com/2014/01/spring-mvc-40-restful-web-services.html


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...