ErrorPageFilter ERROR in log when trying to handle Exception in a spring-boot app -


i've made small spring-boot application , i'm trying add own exception handling. i'm having problem error in log though app works expected. configuration:

  • tomcat 8 (standalone)
  • spring-boot version 1.2.3
  • war packaging

the exception handler looks follows:

@controlleradvice public class globalexceptionhandler {  @responsestatus(httpstatus.not_found) @exceptionhandler(notfoundexception.class) @responsebody errorinfo handlenotfoundrequest(httpservletrequest req, exception ex) {     return new errorinfo(req.getrequesturl().tostring(), ex); }  } 

my controller throws exception:

@requestmapping(value = "/{id}", method = requestmethod.get, produces = {"application/json"}) public @responsebody hashmap environment(@pathvariable("id") long id)  {     hashmap<string, object> map = new hashmap();     environment env = environmentservice.getenvironment(id);      if(env == null) throw new notfoundexception("environment not found: " + id);      map.put("environment", env);      return map; } 

my spring-boot application setup:

@springbootapplication @enableautoconfiguration(exclude=errormvcautoconfiguration.class) @componentscan public class qaapiapplication {  public static void main(string[] args) {     springapplication.run(qaapiapplication.class, args); } } 

servletinitializer:

public class servletinitializer extends springbootservletinitializer {  @override protected springapplicationbuilder configure(springapplicationbuilder   application) {     return application.sources(qaapiapplication.class); } } 

pom.xml

<parent>     <groupid>org.springframework.boot</groupid>     <artifactid>spring-boot-starter-parent</artifactid>     <version>1.2.3.release</version>     <relativepath/> <!-- lookup parent repository --> </parent> ...... <dependency>     <groupid>org.springframework.boot</groupid>     <artifactid>spring-boot-starter-data-jpa</artifactid> </dependency> <dependency>     <groupid>org.springframework.boot</groupid>     <artifactid>spring-boot-starter-jersey</artifactid> </dependency> <dependency>     <groupid>org.springframework.boot</groupid>     <artifactid>spring-boot-starter-web</artifactid> </dependency> 

if call generates exception correct response, 404 expected json. see errorpagefilter error in log:

2015-04-09 21:05:38.647 error 85940 --- [io-8080-exec-16] o.s.boot.context.web.errorpagefilter     : cannot forward error page request [/environments/1] response has been committed. result, response may have wrong status code. if application running on websphere application server may able resolve problem setting com.ibm.ws.webcontainer.invokeflushafterservice false 

there no errors on startup / deployment , seem working far can see. i'm suspecting there default behavior i've not overridden correctly or so, i've yet figure out what. / tip around appreciated i've become stuck on problem be.

if still uses spring-boot version 1.2.3 (not 1.4.2.release solution provided) extend springbootservletinitializer , override method run following:

@springbootapplication @enableautoconfiguration(exclude=errormvcautoconfiguration.class) @componentscan public class qaapiapplication extends springbootservletinitializer {     public static void main(string[] args) {          springapplication.run(qaapiapplication.class, args);     }      @override     protected webapplicationcontext run(springapplication application) {         application.getsources().remove(errorpagefilter.class);         return super.run(application);     } } 

it works me.


Popular posts from this blog