无需使用弹簧靴即可创建弹簧休息服务 [英] creating spring rest services without using spring boot

查看:101
本文介绍了无需使用弹簧靴即可创建弹簧休息服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经按照spring.io上的入门教程来构建REEST服务 https:/ /spring.io/guides/gs/rest-service/ 。问题是本教程仅解释了如何使用spring boot嵌入tomcat来生成独立运行的jar。

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.

有没有办法从头开始创建一个项目来生成一个战争,以便在现有的tomcat实例上进行部署?

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:我找到了一个上一个帖子 Spring RESTful Service作为WAR而不是Tomcat中的JAR 在stackoverflow上涉及同样的问题。问题是接受的答案和建议并没有完全解决我的问题,因为我不是在寻找修改独立应用程序弹簧启动项目的方法,以便它可以在外部tomcat容器上运行,但是想找到一个清洁解决方案根本不涉及弹簧靴。 (我不确定如何在这里表现,在stackoverflow上仍然很新。我希望打开一个新问题是正确的程序。)

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).

推荐答案

你不需要Spring Boot来创建一个休息控制器。

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

请按照spring框架文档了解如何设置MVC
https://docs.spring。 io / spring / docs / current / spring-framework-reference / web.html#spring-web

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

MVC设置( DispatcherServlet )取决于您的spring版本,您可以使用xml,也可以通过编程方式进行设置:
https://docs.spring.io/spring/docs/current/spring-framework-reference/web.html#mvc -servlet

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

一旦设置好,你就可以在您的应用程序中添加休息控制器。请注意,休息控制器( @RestController 注释)是一个构造型注释,它结合了 @ResponseBody @Controller ,换句话说,Controller返回响应体中的对象而不是返回视图。

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.

这是一个完美的例子解释我上面所说的:
http://www.programming-free.com/2014/01/spring-mvc-40-restful-web-services.html

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

这篇关于无需使用弹簧靴即可创建弹簧休息服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆