Global exception in Springboot, System configuration

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.