spring boot项目中踩到的坑

在使用springboot的过程中,遇到过各种各样的小问题。 下面我将我所遇到过得问题做一个小的总结,算是做一个记录。

1.

导包错误导致的启动程序时报错:****Could not autowire. No beans of 'xxxx' type found(或者required a bean of type ‘XXX’ that could not be found)的错误提示

曾经导错的包:import com.alibaba.dubbo.config.annotation.Service;

正确的service包: import org.springframework.stereotype.Service;

正确的mapper包:import org.apache.ibatis.annotations.Mapper;

2.

在application.yml配置文件中使用@ConfigurationProperties(prefix = "user")配置dao对象的默认值时,上方会提示:Spring Boot Configuration Annotation Processor not found in claspath,虽然不影响程序的正常执行,但是在配置文件中为dao对象的属性赋值时,没有自动补全的提示。
image

此时可以在pom文件中增加依赖关系:

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>

此时在配置文件中编辑dao类的属性时,会自动弹出提示,方便键入,避免出错。

3.

pom.xml文件中使用 pagehelper时,启动项目报错,显示依赖循环。
image

查找资料后了解到是pagerhelper的版本和spring boot的版本冲突导致的,可以将spring boot的版本切换到兼容的release版本,此时项目能正常启动。

4.

springboot Invalid character found in the request target 特殊字符传参报错

产生原因: tomcat8.0以上版本遵从RFC规范添加了对Url的特殊字符的限制,url中只允许包含英文字母(a-zA-Z)、数字(0-9)、-_.~四个特殊字符以及保留字符( ! * ’ ( ) ; : @ & = + $ , / ? # [ ] ) (26*2+10+4+18=84)这84个字符,请求中出现了{}大括号或者[],所以tomcat报错。

问题解决:在@SpringBootApplication启动类中增加下述代码

@Bean
public ConfigurableServletWebServerFactory webServerFactory() {
TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
factory.addConnectorCustomizers((TomcatConnectorCustomizer) connector -> connector.setProperty("relaxedQueryChars", "|{}[]\\"));
return factory;
}

问题得到解决。

posted @   哪儿都通张楚岚  阅读(214)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 25岁的心里话
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
点击右上角即可分享
微信分享提示