[英]Spring4 Boot WebService Controller not working with Gradle Tomcat Plugin
我正在嘗試制作一個簡單的Spring4 WebService,這里是基本代碼的要點
https://gist.github.com/jrgleason/1e23b694e0facc123caa
它似乎可以正常啟動,但是當我訪問http://localhost:8080/itext
了404異常。 有人可以幫我解決什么問題嗎? 是因為我正在使用啟動插件嗎?
您的應用程序正在運行,請檢查以下URL: http://localhost:8080/
將您的bean更改為http://localhost:8080/itext
@RestController
public class GreetingController {
@RequestMapping("/itext")
public String test(){
System.out.println("Test");
return "Test";
}
}
在默認情況下,在Spring Boot Tomcat中是嵌入式的,不需要配置tomcat。
問題是Spring-Boot似乎在tomcat-plugin 上不能很好地工作(可以使它工作的響應會搶走它!) 。 如上所述,您可以減少到僅使用彈簧靴...
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.1.1.RELEASE")
}
}
apply plugin: 'war'
apply plugin: 'spring-boot'
war { baseName='itext' }
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
testCompile("org.springframework.boot:spring-boot-starter-test")
}
但是,如果執行此操作,則還需要將Application.java更改為類似以下內容。
package com.gleason.itext;
import java.util.Arrays;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.PathVariable;
@Configuration
@ComponentScan
@EnableAutoConfiguration
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(applicationClass, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(applicationClass);
}
private static Class<Application> applicationClass = Application.class;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.