vendredi 17 avril 2015

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is com.test.core.ApplicationException

I am working on sample demo application for Exception Handling in Spring MVC.I am trying Exception Handling With @ControllerAdvice


But when i run my application i get the following error



org.springframework.web.util.NestedServletException: Request processing failed; nested exception is com.test.core.ApplicationException


For more details following are the classes I am working on


ApplicationException.java



public class ApplicationException extends RuntimeException{


/**
*
*/
private static final long serialVersionUID = -9061684361606685158L;
private ErrorStatus errorStatus;
private int msgNumber;
private Object []args;

public ApplicationException(){}

public ApplicationException(ErrorStatus errorStatus, int msgNumber,
Object[] args) {
this.errorStatus = errorStatus;
this.msgNumber = msgNumber;
this.args = args;
}
//getter setters
}


Controller class


ApplicationExceptionController.java



@Controller
@RequestMapping("/exception")
public class ApplicationExceptionController {

@RequestMapping(value="/error",method=RequestMethod.GET)
@ResponseBody
public void helloException()
{
throw new ApplicationException(ErrorStatus.NotFound,1,new Object[]{"Website"});

//here ErrorStatus is a enum class
}
}


And here is the GlobalExceptionHandler class


GlobalExceptionHandler.java



@ControllerAdvice
public class GlobalExceptionHandler {

@ExceptionHandler
public void notFount(){
System.out.println("----------CaughtApplicationException-----------");
}
}


I run above application with http://localhost:8080/SpringExceptionHandling/exception/error this url


But I get the following Exception



org.springframework.web.util.NestedServletException: Request processing failed; nested exception is com.test.core.ApplicationException
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:894)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

root cause

com.test.core.ApplicationException
com.test.controller.ApplicationExceptionController.helloException(ApplicationExceptionController.java:19)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:214)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:100)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:604)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:565)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)


Please help me to get the solution.I am not getting the actual cause for this exception.


Aucun commentaire:

Enregistrer un commentaire