我将遵循下一个教程:https://spring.io/guides/gs/rest-service/
我注意到他们不使用tomcat来管理他们的项目。他们使用"gradle run“命令来运行它。有可能在tomcat下运行那个Spring项目吗?
另外,我想知道它是否合理。我们是否需要tomcat来运行spring RESTful项目(也许使用"gradle run“命令运行更好)?
我正在使用Intellij和gradle 3.0
我有下一个build.gradle内容:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.4.0.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
jar {
baseName = 'gs-rest-service'
version = '0.1.0'
}
repositories {
jcenter()
maven { url "http://repo.spring.io/libs-snapshot" }
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
}如教程中的所有类
发布于 2016-09-04 00:32:51
如果您想使用Spring提供的嵌入式Tomcat,只需使用spring-boot-starter-web启动程序并使用spring-boot:run运行该项目。
但是,当您按照提供的方式设置spring-boot-starter-tomcat时,我认为您希望使用外部Tomcat。
在这里,您可以找到用于创建战争的文档。您需要使用WAR gradle插件,配置Tomcat实例,并像往常一样使用spring-boot:run运行项目。
如果使用Gradle,则需要修改build.gradle以将war插件应用于项目: 应用插件:“war” 该过程的最后一步是确保嵌入的servlet容器不会干扰war文件将要部署到的servlet容器。为此,需要按照提供的方式标记嵌入式servlet容器依赖项。 依赖关系{ //…'org.springframework.boot:spring-boot-starter-tomcat‘//…}
发布于 2016-09-03 09:28:30
Websphere顾名思义是一个运行在RESTful (HTTP).And上的服务--如果您想在Web上运行任何应用程序,您需要在web上部署它-- SERVER.Tomcat是一个WEB server.Yes,您需要Tomcat(或JBoss、Websphere、Weblogic、...server)来运行SERVER.Tomcat,或者任何RESTful web service.Gradle都是依赖关系管理工具,它可以帮助您构建所需的可执行文件(如Websphere/应用程序中的.war )。
发布于 2016-09-03 09:29:01
我更喜欢使用Idea中的Spring配置来运行Spring项目。
只需创建一个新的运行配置并将Application指定为主类即可。更多信息在官方文档。
但是,您也可以在Tomcat中运行它。这意味着创建Tomcat运行配置并在那里部署产生的war,但是这要麻烦得多。
https://stackoverflow.com/questions/39305293
复制相似问题