我正在使用Spring MVC版本4.1.7构建一组restful服务,尝试使用@RestController作为控制器,所以我不需要@ResponseBody吗?当我包含@ResponseBody时,请求返回true。该项目构建正常,但是当我将它部署到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依赖:这个模块的树:
+- 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
我可以在这里找到什么?
- Update-- 我将战争部署到三个不同的tomcat容器2/3正常工作它只是一个有问题的Tomcat6容器。仍然困惑我,因为我不确定tomcat上的哪些文件会导致这样的问题
答案 0 :(得分:0)
我使用下面的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);;
}
}
答案 1 :(得分:0)
令人尴尬的是,我的问题的解决方案最终成为了tomcat容器的重启。出于何种原因,战争不像其他系统一样自动部署,并且持有旧服务目录。