我在Spring Framework中有一个项目。所有代码都可以在Glassfish中工作,但是当我在Apache Tomcat Plumee上部署它并获得此异常时。项目有什么问题? 我的代码是这样的:
import az.Vortex.SpringDevelopers.dto.MailDTO;
import az.Vortex.SpringDevelopers.dto.UserAddResponse;
import az.Vortex.SpringDevelopers.dto.UserDTO;
import az.Vortex.SpringDevelopers.dto.UserLoginResponseObject;
import az.Vortex.SpringDevelopers.model.User;
import az.Vortex.SpringDevelopers.model.UserRole;
import az.Vortex.SpringDevelopers.model.UserSession;
import az.Vortex.SpringDevelopers.response.CustomException;
import az.Vortex.SpringDevelopers.response.ResponseDTO;
import az.Vortex.SpringDevelopers.service.UserService;
import az.Vortex.SpringDevelopers.service.UserSessionService;
import az.Vortex.SpringDevelopers.utils.MailUtil;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.ws.Response;
import org.apache.commons.lang.StringEscapeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;
import utils.AuthorizationUtil;
import utils.EmailValidator;
import utils.SecurityUtils;
@Controller
@RequestMapping("users")
public class UserController {
@RequestMapping(value = "login", method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody
ResponseDTO loginUser(@RequestBody UserDTO userDto) throws Exception {
System.out.println("login=" + userDto);
ResponseDTO result = new ResponseDTO();
String exStr = "";
if (userDto.getEmail() == null || !EmailValidator.validate(userDto.getEmail())) {
exStr = "email is not filled right";
}
if (userDto.getPassword() == null || userDto.getPassword().length() == 0) {
exStr += " password is not filled right";
}
if (exStr.length() > 0) {
throw new IllegalArgumentException(exStr);
}
User userTemp = new User();
userTemp.setEmail(userDto.getEmail());
userTemp = userService.getUser(userTemp);
if (userTemp == null) {
throw new CustomException("This email doesn't exist", "Email or password is not right");
}
System.out.println(userDto.getPassword());
userTemp.setPassword(userDto.getPassword());
userTemp = userService.getUserForLogin(userTemp);
if (userTemp == null) {
throw new CustomException("Password is incorrect,owner email:" + userDto.getEmail(), "Email or password is not right");
}
result.setResponseObject(addOrUpdateSession(userTemp));
result.setSuccessMessage("Successfully logged in");
return result;
}
}
2016年4月16日下午8:14:54 az.Vortex.SpringDevelopers.filters.CustomExceptionHandler handleAllException 严重:org.springframework.web.HttpMediaTypeNotSupportedException:内容类型' application / json'不支持 org.springframework.web.HttpMediaTypeNotSupportedException:内容类型' application / json'不支持 at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver.readWithMessageConverters(AbstractMessageConverterMethodArgumentResolver.java:149) 在org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.readWithMessageConverters(RequestResponseBodyMethodProcessor.java:180) at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.resolveArgument(RequestResponseBodyMethodProcessor.java:95) 在org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:77) 在org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:162) 在org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:123) 在org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104) 在org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745) 在org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686) 在org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80) 在org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925) 在org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856) 在org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936) 在org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:838) 在javax.servlet.http.HttpServlet.service(HttpServlet.java:650) 在org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812) 在javax.servlet.http.HttpServlet.service(HttpServlet.java:731) 在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) 在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) 在org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) 在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) 在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) 在org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220) 在org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) 在org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44) 在org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44) 在org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44) 在org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44) 在org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44) 在org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44) 在org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44) 在org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44) 在org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44) 在org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44) 在org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44) 在org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505) 在org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169) 在org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) 在org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956) 在org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) 在org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:436) 在org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078) at org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:625) at org.apache.tomcat.util.net.JIoEndpoint $ SocketProcessor.run(JIoEndpoint.java:316) 在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:617) at org.apache.tomcat.util.threads.TaskThread $ WrappingRunnable.run(TaskThread.java:61) 在java.lang.Thread.run(Thread.java:745)
2016年4月16日下午8:14:54 org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver doResolveHandlerMethodException 严重:无法调用@ExceptionHandler方法:public az.Vortex.SpringDevelopers.response.ResponseDTO az.Vortex.SpringDevelopers.filters.CustomExceptionHandler.handleAllException(java.lang.Exception,javax.servlet.http.HttpServletResponse) org.springframework.web.HttpMediaTypeNotAcceptableException:找不到可接受的表示 在org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:157) 在org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:90) 在org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.handleReturnValue(RequestResponseBodyMethodProcessor.java:189) 在org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.java:69) 在org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:122) at org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver.doResolveHandlerMethodException(ExceptionHandlerExceptionResolver.java:321) at org.springframework.web.servlet.handler.AbstractHandlerMethodExceptionResolver.doResolveException(AbstractHandlerMethodExceptionResolver.java:60) at org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver.resolveException(AbstractHandlerExceptionResolver.java:136) at org.springframework.web.servlet.handler.HandlerExceptionResolverComposite.resolveException(HandlerExceptionResolverComposite.java:73) 在org.springframework.web.servlet.DispatcherServlet.processHandlerException(DispatcherServlet.java:1148) 在org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:985) 在org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:939) 在org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856) 在org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936) 在org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:838) 在javax.servlet.http.HttpServlet.service(HttpServlet.java:650) 在org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812) 在javax.servlet.http.HttpServlet.service(HttpServlet.java:731) 在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) 在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) 在org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) 在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) 在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) 在org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220) 在org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) 在org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44) 在org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44) 在org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44) 在org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44) 在org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44) 在org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44) 在org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44) 在org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44) 在org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44) 在org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44) 在org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44) 在org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505) 在org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169) 在org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) 在org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956) 在org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) 在org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:436) 在org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078) at org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:625) at org.apache.tomcat.util.net.JIoEndpoint $ SocketProcessor.run(JIoEndpoint.java:316) 在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:617) at org.apache.tomcat.util.threads.TaskThread $ WrappingRunnable.run(TaskThread.java:61) 在java.lang.Thread.run(Thread.java:745)
答案 0 :(得分:0)
我解决了我的问题。我添加了这种依赖:
<dependency> <groupId>org.codehaus.jackson</groupId> <artifactId>jackson-mapper-asl</artifactId> <version>1.9.10</version> </dependency>