>我在Spring Boor中从RestController设置HEAD resposnse时遇到问题。我目前正在使用Spring Boot 1.5.9版本。
我已经解决了解决这个问题的新项目。在应用程序属性中,我只有一行:
server.context-path=/api/v1
My RestController "TestController.java">
@RestController
public class TestController {
@GetMapping("/test")
public String test() {
return "test";
}
}
当我尝试在 url http://localhost:8080/api/v1/test 上仅获取带有 HTTP HEAD 请求的标头时,响应堆栈和我没有得到任何响应。在应用控制台中没有错误。
如果我从应用程序属性中删除 server.context-path=/api/v1。然后,对 http://localhost:8080/test 的 HEAD 请求正在按预期工作。
感谢您的任何帮助,马丁
这里是 build.gradle
buildscript {
ext {
springBootVersion = '1.5.9.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-websocket')
// compile('com.microsoft.sqlserver:sqljdbc4')
runtime('org.springframework.boot:spring-boot-devtools')
testCompile('org.springframework.boot:spring-boot-starter-test')
}