【问题标题】:properties files are used in Spring Boot在 Spring Boot 中使用属性文件
【发布时间】:2018-03-01 05:46:29
【问题描述】:

application.properties文件中这些属性有什么用 我们什么时候使用它们?

spring.mvc.throw-exception-if-no-handler-found=true
spring.sources.add-mappings=false

【问题讨论】:

标签: java spring spring-mvc spring-boot


【解决方案1】:

根据这些资源

  1. disable the static resource handling in Spring Boot

  2. Spring Boot application-properties

你可以使用

spring.resources.add-mappings=false

用于禁用对类路径/ JAR/ 文件系统资源(如css 或图像文件)的默认处理,以防您想限制对它们的访问并创建自己的映射

spring.mvc.throw-exception-if-no-handler-found=true

如果您希望在处理 request 时没有找到 handler 时抛出 NoHandlerFoundException 类型的异常(并且可能捕获它并采取相同的适当操作)。

【讨论】:

  • 您可以通过在 application.properties 中设置 spring.resources.add-mappings=false 来禁用静态资源处理。有了这个,你确定它会解决你的问题吗? Spring Security 在静态资源处理之前作为过滤器运行,我怀疑禁用资源处理会有所帮助。不过,也许它会更容易识别潜在问题。
猜你喜欢
  • 1970-01-01
  • 2017-11-06
  • 2016-04-29
  • 1970-01-01
  • 2020-12-12
  • 2018-08-01
  • 2021-11-27
  • 1970-01-01
  • 2020-07-30
相关资源
最近更新 更多