简体   繁体   English

如何使用 gradle.build 文件运行 spring-boot 服务?

[英]How to run a spring-boot service with gradle.build file?

I was given a spring-boot project and told to run it in intellij.我得到了一个 spring-boot 项目,并被告知在 intellij 中运行它。 I have the project open in intellij.我在intellij中打开了该项目。 When I click on the gradle.build file I select run and the project compiles.当我单击 gradle.build 文件时,我运行select 并编译项目。

Expected:预期的:

When I click run on the project I expected the editor to run a local webserver and display "Greetings from Greetings from ZprIng booTI, ${req.remoteAddr}".当我单击项目上的运行时,我希望编辑器运行本地网络服务器并显示“来自 ZprIng booTI 的问候,${req.remoteAddr}”。 Given that the ZitiSpringBootApplication.kt is鉴于ZitiSpringBootApplication.kt

/*
 * Copyright (c) 2018-2021 NetFoundry Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.openziti.sample.springboot

import org.openziti.springboot.ZitiTomcatCustomizer
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RestController
import javax.servlet.http.HttpServletRequest


@SpringBootApplication(
    scanBasePackageClasses = [
        ZitiTomcatCustomizer::class,
        HelloController::class
    ]
)
class ZitiSpringBootApplication


@RestController
class HelloController {
    @GetMapping("/")
    fun index(req: HttpServletRequest): String {
        return "Greetings from ZprIng booTI, ${req.remoteAddr}"
    }
}

Actual实际的

Here is a screenshot from intellij这是来自intellij的截图

在此处输入图像描述

As you can see the build was successful.如您所见,构建成功。 How do I run the web service from the editor?如何从编辑器运行 web 服务? Any help would be greatly appreciated.任何帮助将不胜感激。

you need to run the main function class of the project in order to run the webserver您需要运行项目的主要 function class 才能运行网络服务器

I gave up trying to run this in intellij.我放弃了尝试在 intellij 中运行它。 The answer above doesn't make any sense.上面的答案没有任何意义。 I ran the project from the command line using./gradlew bootRun.我使用 ./gradlew bootRun 从命令行运行项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM