springBoot 配置文件 spring.mvc.throw-exception-if-no-handler-found 参数的作用

在这里插入图片描述
在Spring Boot应用中,可以通过配置文件来控制当找不到请求处理器(handler)时是否抛出异常。具体的配置参数是spring.mvc.throw-exception-if-no-handler-found

默认情况下,该参数的值为false,即当找不到请求处理器时,Spring MVC会返回404 Not Found响应。如果将该参数设置为true,则当找不到请求处理器时,Spring MVC会抛出NoHandlerFoundException异常。

以下是对该配置参数的不同取值的说明:

  • spring.mvc.throw-exception-if-no-handler-found=true:当找不到请求处理器时,Spring MVC会抛出NoHandlerFoundException异常,并且可以自定义一个异常处理器来处理该异常。
  • spring.mvc.throw-exception-if-no-handler-found=false(默认值):当找不到请求处理器时,Spring MVC会返回404 Not Found响应,客户端会收到一个简单的HTTP错误响应。

通常情况下,设置为默认值即可,当找不到请求处理器时返回404响应是比较合理和常见的做法。如果有特殊需求,例如需要在找不到处理器时抛出异常以便进行其他处理,可以将该参数设置为true

# ???? WEB ???? server.port=7090 server.servlet.context-path=/api #session???? 60M ???? server.servlet.session.timeout=PT60M #??favicon spring.mvc.favicon.enable=false #???? spring.mvc.throw-exception-if-no-handler-found=true spring.web.resources.add-mappings=false spring.servlet.multipart.max-file-size=20MB spring.servlet.multipart.max-request-size=20MB #数据库设置 spring.datasource.url=jdbc:mysql://118.24.147.138:3306/wangpan?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&autoReconnect=true&allowMultiQueries=true spring.datasource.username=wangpan spring.datasource.password=rootroot spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.hikari.pool-name=HikariCPDatasource spring.datasource.hikari.minimum-idle=5 spring.datasource.hikari.idle-timeout=180000 spring.datasource.hikari.maximum-pool-size=10 spring.datasource.hikari.auto-commit=true spring.datasource.hikari.max-lifetime=1800000 spring.datasource.hikari.connection-timeout=30000 spring.datasource.hikari.connection-test-query=SELECT 1 #???????? # ?????????? smtp.qq.com spring.mail.host=smtp.qq.com # ??????? spring.mail.port=465 # ??? spring.mail.username=3824245251@qq.com # spring.mail.password=ehcyxusufuulccah # ???? spring.mail.default-encoding=UTF-8 # SSL???? spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory # ?? debug???????????????? spring.mail.properties.mail.debug=true #?????? #Spring redis?? # Redis?????????0? spring.redis.database=0 spring.redis.host=118.24.147.138 spring.redis.port=6379 # ???????????????????? spring.redis.jedis.pool.max-active=20 # ??????????????????????? spring.redis.jedis.pool.max-wait=-1 # ??????????? spring.redis.jedis.pool.max-idle=10 # ??????????? spring.redis.jedis.pool.min-idle=0 # ?????????? spring.redis.timeout=2000 #项目目录 project.folder=/www/wangpan/ # log.root.level=debug #内部端口 inner.api.appKey=wangpan inner.api.appSecret=wangpan_key #web端口 web.api.url=http://118.24.147.138:7090 #管理员id admin.emails=961285867@qq.com #是否是开发环境 dev=false ##qq????## qq.app.id=12333 qq.app.key=2222222 qq.url.authorization=https://graph.qq.com/oauth2.0/authorize?response_type=code&client_id=%s&redirect_uri=%s&state=%s qq.url.access.token=https://graph.qq.com/oauth2.0/token?grant_type=authorization_code&client_id=%s&client_secret=%s&code=%s&redirect_uri=%s qq.url.openid=https://graph.qq.com/oauth2.0/me?access_token=%S qq.url.user.info=https://graph.qq.com/user/get_user_info?access_token=%s&oauth_consumer_key=%s&openid=%s qq.url.redirect=http://wangpan.wuhancoder.com/qqlogincalback springboot配置文件,部署到服务器上,有什么错误吗
最新发布
05-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

羽露风

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值