我想在這裏做一個簡單的Spring4 web服務的基本代碼要點Spring4啓動WebService的控制器不搖籃Tomcat插件工作
https://gist.github.com/jrgleason/1e23b694e0facc123caa
它似乎開始OK,但是當我訪問http://localhost:8080/itext
我得到一個404例外。有人能幫我解決什麼問題嗎?是因爲我使用啓動插件嗎?
我想在這裏做一個簡單的Spring4 web服務的基本代碼要點Spring4啓動WebService的控制器不搖籃Tomcat插件工作
https://gist.github.com/jrgleason/1e23b694e0facc123caa
它似乎開始OK,但是當我訪問http://localhost:8080/itext
我得到一個404例外。有人能幫我解決什麼問題嗎?是因爲我使用啓動插件嗎?
你的應用是否有效,檢查此網址:
改變你的bean爲http://localhost:8080/itext
@RestController
public class GreetingController {
@RequestMapping("/itext")
public String test(){
System.out.println("Test");
return "Test";
}
}
在春天啓動的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;
}
需要注意的是,bootrun並沒有在cygwin中正常停止,可以很好地與cmd一起工作 – Jackie