I downloaded demo webapp from https://start.spring.io/ (gradle kotlin project). Added 2 controllers for '/' and '/test' just to test if everything is OK. Here is the code:
@Controller
class IndexController {
@ResponseBody
@GetMapping("/")
fun main() : String {
return "Hello World"
}
@Controller
class TestController {
@ResponseBody
@GetMapping("/test")
fun main() : String {
return "test"
}
Then i added war plugin to gradle
apply plugin: 'war'
Then i print to terminal
gradlew build
and in build/libs found .war file. I deployed it to locat Tomcat, but
http://localhost:8080/demo-0.0.1-SNAPSHOT/
http://localhost:8080/demo-0.0.1-SNAPSHOT/test
respond with 404 error.
In IDEA i can easy start my app and see Hello World and test.
Any ideas?
[JAR file]
You are missing imports in controller.
put below imports in your controller.
package com.example.demo
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
now remove the plugin apply plugin: 'war'
and build project using gradlew build
it will create a jar file inside app_name\\build\\libs
open this location in command prompt and run below command.
java -jar <jar_file_name>.java
open application using below url.
http://localhost:8080
[WAR file]
extend SpringBootServletInitializer as below
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
@SpringBootApplication
class DemoApplication : SpringBootServletInitializer()
put the plugin apply plugin: 'war'
and build project using gradlew build
now inside app_name\\build\\libs it will create a war file.
deploy this war to tomcat server and access using below URL:
http://localhost:8080/demo-0.0.1-SNAPSHOT/
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.