Exceptions in 1.springboot
Package Com.ithuan.demo;import Javax.servlet.http.httpservletrequest;import Org.springframework.web.bind.annotation.controlleradvice;import Org.springframework.web.bind.annotation.exceptionhandler;import org.springframework.web.bind.annotation.responsebody;/** * 1, create a new class, here named Globaldefaultexceptionhandler * 2, Add annotations on class, @ControllerAdvice; * 3, add a method in class * 4, add @excetionhandler on the method to intercept the corresponding exception information; * 5, if the return is a view-the return value of the method is Modelandview; * 6, if the return is a string or JSON data, then you need to add @responsebody annotations on the method. */@ControllerAdvicepublic class myexception {@ Exceptionhandler (value = exception.class) @ResponseBodypublic String MyMethod (httpservletrequest req, Exception e) { Return "service is not common";}}
Common configurations in Springboot
# #端口号设置 #server.port=8080#server.address= # bind to a specific nic#server.session-timeout= # session timeout in seconds#th e context path, defaults to '/' #server. Context-path=/spring-boot#server.servlet-path= # of the servlet path, defaults to '/' # server.tomcat.access-log-pattern= # Log pattern of the Access Log#server.tomcat.access-log-enabled=false # is Access Logg ing Enabled#server.tomcat.protocol-header=x-forwarded-proto # SSL forward headers#server.tomcat.remote-ip-header= X-forwarded-for#server.tomcat.basedir=/tmp # base Dir (usually not needed, defaults to TMP) # server.tomcat.background-processor-delay=30; # in seconds#server.tomcat.max-threads = 0 # Number of threads in Protocol handler# #编码 #server.tomcat.uri-encoding = UTF-8 # character encoding to use for URL decoding
Global exception in Springboot, System configuration