【问题标题】:How to run a spring-boot service with gradle.build file?如何使用 gradle.build 文件运行 spring-boot 服务?
【发布时间】:2021-12-28 18:57:40
【问题描述】:

我得到了一个 spring-boot 项目,并被告知在 intellij 中运行它。我在intellij中打开了该项目。当我点击 gradle.build 文件时,我选择 run 并且项目编译。

预期:

当我在项目上单击运行时,我希望编辑器运行本地网络服务器并显示“Greetings from Greetings from ZprIng booTI, ${req.remoteAddr}”。鉴于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}"
    }
}

实际

这是来自 intellij 的截图

如您所见,构建成功。如何从编辑器运行 Web 服务?任何帮助将不胜感激。

【问题讨论】:

标签: java spring spring-boot intellij-idea


【解决方案1】:

您需要运行项目的主要功能类才能运行网络服务器

【讨论】:

    【解决方案2】:

    我放弃了尝试在 intellij 中运行它。上面的答案没有任何意义。我使用 ./gradlew bootRun 从命令行运行项目。

    【讨论】:

      猜你喜欢
      • 2018-02-21
      • 2020-04-21
      • 1970-01-01
      • 2016-01-27
      • 2016-04-30
      • 2017-07-16
      • 2015-04-09
      • 2021-06-27
      • 2019-02-13
      相关资源
      最近更新 更多