Luk*_*ker 3 java rest spring controller spring-mvc
我仅因一项服务而遇到此异常。我的控制器中有两项服务,另一项工作正常。
\n\n@Controller\n@RequestMapping("/document")\npublic class DocumentController {\n\n@Autowired\nprivate PdfService pdfService;\n\n@Autowired\nprivate MailService mailService;\n\n@Autowired\nprivate TransaccionService transaccionService;\n\n@Autowired\nprivate UsuarioService usuarioService;\n\n@RequestMapping(value = "/export", method = RequestMethod.GET)\npublic void exportAutorizacion(HttpServletRequest request){\n TicketAutorizacionDto ticket = (TicketAutorizacionDto) request.getSession().getAttribute("ticketAutorizacion");\n this.pdfService.createPdf(ticket);\n\n}\n\n@RequestMapping(value = "/email/{numeroAutorizacion}", method = RequestMethod.PUT)\npublic Boolean enviarMail(@PathVariable("numeroAutorizacion") Integer numeroAutorizacion,@ModelAttribute EmailsForm mails){\n\n if(mails.getEmails().isEmpty() || numeroAutorizacion == null){\n return false;\n }\n\n UsuarioForm usuarioForm = null;\n Authentication auth = SecurityContextHolder.getContext().getAuthentication();\n try {\n usuarioForm = this.usuarioService.getUsuarioByNombreUsuario(auth.getName());\n TicketAutorizacionDto ticket = this.transaccionService.getTicketAutorizacion(numeroAutorizacion, usuarioForm.getIdBeneficiario());\n return this.mailService.enviarOrdenMedica(ticket, mails.getEmails().toArray(new String[mails.getEmails().size()]));\n } catch (NoExisteBeneficiarioException e) {\n e.printStackTrace();\n }\n\n return false;\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n\n和 XML:
\n\n<mvc:annotation-driven />\n<tx:annotation-driven />\n<!-- <context:property-placeholder -->\n<!-- properties-ref="deployProperties" /> -->\n\n<!-- Activates various annotations to be detected in bean classes -->\n<!-- <context:annotation-config /> -->\n\n<!-- Scans the classpath for annotated components that will be auto-registered \n as Spring beans. For example @Controller and @Service. Make sure to set the \n correct base-package -->\n<context:component-scan base-package="ar.com.conexia.salud.*" />\n\n<jpa:repositories base-package="ar.com.conexia.salud.repository" />\n<!-- Configures the annotation-driven Spring MVC Controller programming \n model. Note that, with Spring 3.0, this tag works in Servlet MVC only! -->\n<mvc:annotation-driven />\n<!-- Imports datasource configuration -->\n<!-- <import resource="spring-data.xml" /> -->\n\n<mvc:resources mapping="/resources/**" location="/resources/" />\n<!-- Imports logging configuration -->\n<!-- <import resource="trace-context.xml" /> -->\n\n\n<!-- <bean id="deployProperties" -->\n<!-- class="org.springframework.beans.factory.config.PropertiesFactoryBean" -->\n<!-- p:location="/WEB-INF/spring.properties" /> -->\n\n<bean id="multipartResolver"\n class="org.springframework.web.multipart.commons.CommonsMultipartResolver">\n</bean>\n\n<bean id="messageSource"\n class="org.springframework.context.support.ResourceBundleMessageSource">\n <property name="basenames">\n <list>\n <value>messages</value>\n </list>\n </property>\n</bean>\n<bean id="localeChangeInterceptor" class="ar.com.conexia.salud.interceptors.LanguageInterceptor">\n <property name="paramName" value="lang" />\n</bean>\n<bean id="userDetailsServiceImpl" class="ar.com.conexia.salud.security.UserServiceImpl">\n\n</bean>\n<bean id="localeResolver"\n class="org.springframework.web.servlet.i18n.SessionLocaleResolver">\n <property name="defaultLocale" value="es" />\n</bean>\n<mvc:interceptors>\n <bean class="ar.com.conexia.salud.interceptors.LanguageInterceptor">\n <property name="paramName" value="lang" />\n </bean>\n</mvc:interceptors>\n\n\n<bean id="transactionTrasmitter"\n class="ar.com.conexia.salud.transmitter.COMEITransactionTransmitter">\n <property name="serverPort" value="2012" />\n <property name="timeout" value="300000" />\n <property name="password" value="conexia" />\n <property name="serverIP" value="192.168.0.97" />\n <!-- <property name="serverIP" value="localhost"/> -->\n <property name="msjKey" value="C:\\\\mySrvKeystore" />\n <!-- <property name="msjKey" value="/usr/local/mySrvKeystore" /> -->\n</bean>\n\n<bean id="basePath" class="java.lang.String">\n <constructor-arg\n value="#{systemProperties[\'catalina.home\']}/webapps/COMEI_Beneficiario" />\n</bean>\n\n<bean id="pdfGenerator" class="ar.com.conexia.generator.PdfGenerator">\n <constructor-arg value="/WEB-INF/classes/reports/" />\n <constructor-arg value="C://reports//" />\n</bean>\n\n<bean id="emailConfiguration" class="ar.com.conexia.salud.dto.EmailConfigurationDto">\n <property name="port" value="25" />\n <property name="auth" value="true" />\n <property name="starttls" value="true" />\n <property name="host" value="192.168.0.10" />\n <property name="user" value="smtpcomei@conexia.com.ar" />\n <property name="pass" value="" />\n</bean>\nRun Code Online (Sandbox Code Playgroud)\n\n\n\n有任何想法吗?
\n\n谢谢!
\n\n编辑:这是抛出异常的完整堆栈。
\n\nSEVERE: El Servlet.service() para el servlet [dispatcher] en el contexto con ruta [/COMEI_Beneficiario] lanz\xc3\xb3 la excepci\xc3\xb3n [No adapter for handler [public java.lang.Boolean ar.com.conexia.salud.controller.DocumentController.enviarMail(java.lang.Integer)]: Does your handler implement a supported interface like Controller?] con causa ra\xc3\xadz\njavax.servlet.ServletException: No adapter for handler [public java.lang.Boolean ar.com.conexia.salud.controller.DocumentController.enviarMail(java.lang.Integer)]: Does your handler implement a supported interface like Controller?\n at org.springframework.web.servlet.DispatcherServlet.getHandlerAdapter(DispatcherServlet.java:1077)\n at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:870)\n at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:827)\n at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)\n at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)\n at javax.servlet.http.HttpServlet.service(HttpServlet.java:620)\n at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)\n at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)\n at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)\n at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)\n at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)\n at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)\n at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:311)\n at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:116)\n at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)\n at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)\n at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)\n at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)\n at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:101)\n at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)\n at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)\n at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)\n at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)\n at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)\n at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)\n at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)\n at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150)\n at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)\n at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:182)\n at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)\n at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)\n at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)\n at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)\n at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)\n at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:173)\n at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)\n at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)\n at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)\n at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)\n at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)\n at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)\n at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)\n at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)\n at com.opensymphony.sitemesh.webapp.SiteMeshFilter.obtainContent(SiteMeshFilter.java:129)\n at com.opensymphony.sitemesh.webapp.SiteMeshFilter.doFilter(SiteMeshFilter.java:77)\n at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)\n at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)\n at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)\n at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)\n at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)\n at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)\n at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)\n at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)\n at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)\n at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)\n at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)\n at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)\n at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)\n at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)\n at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)\n at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)\n at java.lang.Thread.run(Thread.java:722)\nRun Code Online (Sandbox Code Playgroud)\n
为什么要尝试从控制器方法返回布尔值?该方法是否服务休息请求?在这种情况下,需要使用 @ResponseBody 进行注释,或者如果您使用的是 Spring 4.x,请将 @Controller 更改为 @RestController。如果这不是休息服务,我认为您无法返回布尔值。您必须返回 String 或 ModelAndView 对象。
| 归档时间: |
|
| 查看次数: |
19505 次 |
| 最近记录: |