Spring 版本错误?
Wrong Spring version?
我正在使用 Spring MVC 版本 4.1.7 构建一组 restful 服务,试图将 @RestController 用于控制器,所以我不需要 @ResponseBody 对吧?当我包含@ResponseBody 时,请求 returns 为真。该项目构建良好,但是当我将它部署到 tomcat 尝试达到我的端点时,它会抛出一个异常,我不希望 4.1.7
控制器:
@RestController
public class IsAliveController {
@RequestMapping(value = "/isalive", method = RequestMethod.GET)
public Boolean isAlive() {
return true;
}
}
错误(为什么是 3.2.9.RELEASE 版本?):
java.lang.IllegalArgumentException: Unknown return value type [java.lang.Boolean]
at org.springframework.util.Assert.notNull(Assert.java:112) ~[spring-core-3.2.9.RELEASE.jar:3.2.9.RELEASE]
at org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.java:68) ~[spring-web-3.2.9.RELEASE.jar:3.2.9.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:122) ~[spring-webmvc-3.2.9.RELEASE.jar:3.2.9.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745) ~[spring-webmvc-3.2.9.RELEASE.jar:3.2.9.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:685) ~[spring-webmvc-3.2.9.RELEASE.jar:3.2.9.RELEASE]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80) ~[spring-webmvc-3.2.9.RELEASE.jar:3.2.9.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:919) ~[spring-webmvc-3.2.9.RELEASE.jar:3.2.9.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:851) ~[spring-webmvc-3.2.9.RELEASE.jar:3.2.9.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:953) [spring-webmvc-3.2.9.RELEASE.jar:3.2.9.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:844) [spring-webmvc-3.2.9.RELEASE.jar:3.2.9.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617) [servlet-api.jar:na]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:829) [spring-webmvc-3.2.9.RELEASE.jar:3.2.9.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) [servlet-api.jar:na]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) [catalina.jar:6.0.26]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:6.0.26]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) [catalina.jar:6.0.26]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) [catalina.jar:6.0.26]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) [catalina.jar:6.0.26]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [catalina.jar:6.0.26]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [catalina.jar:6.0.26]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) [catalina.jar:6.0.26]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852) [tomcat-coyote.jar:6.0.26]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588) [tomcat-coyote.jar:6.0.26]
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:396) [tomcat-coyote.jar:6.0.26]
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [na:1.8.0_102]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [na:1.8.0_102]
at java.lang.Thread.run(Unknown Source) [na:1.8.0_102]
此模块的 mvn dependency:tree:
+- org.springframework:spring-core:jar:4.1.7.RELEASE:compile
+- org.springframework:spring-web:jar:4.1.7.RELEASE:compile
| \- org.springframework:spring-context:jar:4.1.7.RELEASE:compile
+- org.springframework:spring-webmvc:jar:4.1.7.RELEASE:compile
| \- org.springframework:spring-expression:jar:4.1.7.RELEASE:compile
+- org.springframework:spring-beans:jar:4.1.7.RELEASE:compile
+- org.springframework.ws:spring-ws-security:jar:2.1.4.RELEASE:compile
| +- org.springframework.ws:spring-ws-core:jar:2.1.4.RELEASE:compile
| | +- org.springframework.ws:spring-xml:jar:2.1.4.RELEASE:compile
| | +- org.springframework:spring-oxm:jar:4.1.7.RELEASE:compile
| | \- wsdl4j:wsdl4j:jar:1.6.1:compile
| +- org.springframework:spring-tx:jar:4.1.7.RELEASE:compile
| +- org.apache.ws.security:wss4j:jar:1.6.14:compile
| | +- org.apache.santuario:xmlsec:jar:1.5.6:compile
| | \- org.opensaml:opensaml:jar:2.5.1-1:compile
| | \- org.opensaml:openws:jar:1.4.2-1:compile
| | \- org.opensaml:xmltooling:jar:1.3.2-1:compile
| +- org.springframework.security:spring-security-core:jar:3.1.0.RELEASE:compile
| | \- org.springframework.security:spring-security-crypto:jar:3.1.0.RELEASE:compile
| \- javax.xml.stream:stax-api:jar:1.0-2:compile
+- org.springframework:spring-aop:jar:4.1.7.RELEASE:compile
| \- aopalliance:aopalliance:jar:1.0:compile
+- javax.validation:validation-api:jar:1.1.0.Final:compile
我可能在这里遗漏了什么?
--更新--
我将 war 部署到三个不同的 tomcat 容器 2/3 工作正常,它只是一个有问题的 Tomcat6 容器。仍然让我感到困惑,因为我不确定 tomcat 上的哪些文件会导致这样的问题
我像下面这样使用 RestController,这应该也适合你。
import org.springframework.http.ResponseEntity;
@RestController
public class IsAliveController {
@RequestMapping(value = "/isalive", method = RequestMethod.GET)
public ResponseEntity<Boolean> isAlive() {
return new ResponseEntity<>(Boolean.TRUE, HttpStatus.OK);;
}
}
令人尴尬的是,我的问题的解决方案最终是重新启动 tomcat 容器。无论出于何种原因,war 都不像其他系统那样 auto-deploying,并且一直保留在旧目录中以供服务使用。
我正在使用 Spring MVC 版本 4.1.7 构建一组 restful 服务,试图将 @RestController 用于控制器,所以我不需要 @ResponseBody 对吧?当我包含@ResponseBody 时,请求 returns 为真。该项目构建良好,但是当我将它部署到 tomcat 尝试达到我的端点时,它会抛出一个异常,我不希望 4.1.7
控制器:
@RestController
public class IsAliveController {
@RequestMapping(value = "/isalive", method = RequestMethod.GET)
public Boolean isAlive() {
return true;
}
}
错误(为什么是 3.2.9.RELEASE 版本?):
java.lang.IllegalArgumentException: Unknown return value type [java.lang.Boolean]
at org.springframework.util.Assert.notNull(Assert.java:112) ~[spring-core-3.2.9.RELEASE.jar:3.2.9.RELEASE]
at org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.java:68) ~[spring-web-3.2.9.RELEASE.jar:3.2.9.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:122) ~[spring-webmvc-3.2.9.RELEASE.jar:3.2.9.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745) ~[spring-webmvc-3.2.9.RELEASE.jar:3.2.9.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:685) ~[spring-webmvc-3.2.9.RELEASE.jar:3.2.9.RELEASE]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80) ~[spring-webmvc-3.2.9.RELEASE.jar:3.2.9.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:919) ~[spring-webmvc-3.2.9.RELEASE.jar:3.2.9.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:851) ~[spring-webmvc-3.2.9.RELEASE.jar:3.2.9.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:953) [spring-webmvc-3.2.9.RELEASE.jar:3.2.9.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:844) [spring-webmvc-3.2.9.RELEASE.jar:3.2.9.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617) [servlet-api.jar:na]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:829) [spring-webmvc-3.2.9.RELEASE.jar:3.2.9.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) [servlet-api.jar:na]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) [catalina.jar:6.0.26]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:6.0.26]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) [catalina.jar:6.0.26]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) [catalina.jar:6.0.26]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) [catalina.jar:6.0.26]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [catalina.jar:6.0.26]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [catalina.jar:6.0.26]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) [catalina.jar:6.0.26]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852) [tomcat-coyote.jar:6.0.26]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588) [tomcat-coyote.jar:6.0.26]
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:396) [tomcat-coyote.jar:6.0.26]
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [na:1.8.0_102]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [na:1.8.0_102]
at java.lang.Thread.run(Unknown Source) [na:1.8.0_102]
此模块的 mvn dependency:tree:
+- org.springframework:spring-core:jar:4.1.7.RELEASE:compile
+- org.springframework:spring-web:jar:4.1.7.RELEASE:compile
| \- org.springframework:spring-context:jar:4.1.7.RELEASE:compile
+- org.springframework:spring-webmvc:jar:4.1.7.RELEASE:compile
| \- org.springframework:spring-expression:jar:4.1.7.RELEASE:compile
+- org.springframework:spring-beans:jar:4.1.7.RELEASE:compile
+- org.springframework.ws:spring-ws-security:jar:2.1.4.RELEASE:compile
| +- org.springframework.ws:spring-ws-core:jar:2.1.4.RELEASE:compile
| | +- org.springframework.ws:spring-xml:jar:2.1.4.RELEASE:compile
| | +- org.springframework:spring-oxm:jar:4.1.7.RELEASE:compile
| | \- wsdl4j:wsdl4j:jar:1.6.1:compile
| +- org.springframework:spring-tx:jar:4.1.7.RELEASE:compile
| +- org.apache.ws.security:wss4j:jar:1.6.14:compile
| | +- org.apache.santuario:xmlsec:jar:1.5.6:compile
| | \- org.opensaml:opensaml:jar:2.5.1-1:compile
| | \- org.opensaml:openws:jar:1.4.2-1:compile
| | \- org.opensaml:xmltooling:jar:1.3.2-1:compile
| +- org.springframework.security:spring-security-core:jar:3.1.0.RELEASE:compile
| | \- org.springframework.security:spring-security-crypto:jar:3.1.0.RELEASE:compile
| \- javax.xml.stream:stax-api:jar:1.0-2:compile
+- org.springframework:spring-aop:jar:4.1.7.RELEASE:compile
| \- aopalliance:aopalliance:jar:1.0:compile
+- javax.validation:validation-api:jar:1.1.0.Final:compile
我可能在这里遗漏了什么?
--更新-- 我将 war 部署到三个不同的 tomcat 容器 2/3 工作正常,它只是一个有问题的 Tomcat6 容器。仍然让我感到困惑,因为我不确定 tomcat 上的哪些文件会导致这样的问题
我像下面这样使用 RestController,这应该也适合你。
import org.springframework.http.ResponseEntity;
@RestController
public class IsAliveController {
@RequestMapping(value = "/isalive", method = RequestMethod.GET)
public ResponseEntity<Boolean> isAlive() {
return new ResponseEntity<>(Boolean.TRUE, HttpStatus.OK);;
}
}
令人尴尬的是,我的问题的解决方案最终是重新启动 tomcat 容器。无论出于何种原因,war 都不像其他系统那样 auto-deploying,并且一直保留在旧目录中以供服务使用。