简体   繁体   中英

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. I have the project open in intellij. When I click on the gradle.build file I select run and the project compiles.

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}". Given that the ZitiSpringBootApplication.kt is

/*
 * 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

在此处输入图像描述

As you can see the build was successful. How do I run the web service from the editor? Any help would be greatly appreciated.

you need to run the main function class of the project in order to run the webserver

I gave up trying to run this in intellij. The answer above doesn't make any sense. I ran the project from the command line using./gradlew bootRun.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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