網站首頁 編程語言 正文
概述
現象
Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986
原因
SpringBoot 2.0.0 以上都采用內置tomcat8.0以上版本,而tomcat8.0以上版本遵從RFC規范添加了對Url的特殊字符的限制,url中只允許包含英文字母(a-zA-Z)、數字(0-9)、-_.~四個特殊字符以及保留字符( ! * ’ ( ) ; : @ & = + $ , / ? # [ ] ) (262+10+4+18=84)這84個字符,請求中出現了{}大括號或者[],所以tomcat報錯。設置RelaxedQueryChars允許此字符(建議),設置requestTargetAllows選項(Tomcat 8.5中不推薦)。 根據Tomcat文檔,下面提供一種方法來設置松弛的QueryChars屬性。
解決方案
在啟動類中添加ConfigurableServletWebServerFactory Bean對象。
@SpringBootApplication
@EnableScheduling
@EnableFeignClients
public class ZhAlarmApplication {
public static void main(String[] args) {
ApplicationContext context = SpringApplication.run(ZhAlarmApplication.class, args);
SpringContextUtil.setApplicationContext(context);
}
@Bean
public ConfigurableServletWebServerFactory webServerFactory() {
TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
factory.addConnectorCustomizers((TomcatConnectorCustomizer) connector -> connector.setProperty("relaxedQueryChars", "|{}[]\\"));
return factory;
}
}
參考
spring boot 中解決 Invalid character found in the request target 異常
原文鏈接:https://blog.csdn.net/tianzhonghaoqing/article/details/125806385
相關推薦
- 2022-11-22 Golang?Compare?And?Swap算法詳細介紹_Golang
- 2022-06-22 Android開發保存QQ密碼功能_Android
- 2022-10-04 解決Pandas生成Excel時的sheet問題的方法總結_python
- 2022-06-15 golang?gorm的關系關聯實現示例_Golang
- 2021-12-02 docker容器時區錯誤問題_docker
- 2023-04-12 詳解在SpringBoot如何優雅的使用多線程_python
- 2023-03-29 Python-apply(lambda?x:?)的使用及說明_python
- 2023-02-17 linux?命令中的大于號、小于號的作用及代表的意思_linux shell
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支