个人向:spring的报错点及其解决,仅供参考

文章讨论了Spring框架中常见的运行时异常,如bean定义错误、依赖冲突、数据源问题、测试类异常等,并提供了相应的解决方法,包括检查配置、版本兼容和处理多处理器映射等问题。

Spring

No Such Bean Definition Exception: 没有这样的bean 定义异常;(字母写错了,可能是大小写问题)

Illegal State Exception:非法状态异常

No Such Bean Definition Exception: No qualifying bean of type 'com . alibaba . druid . pool .Druid Data Source' available (没有注解 @Bean)

org.springframework.beans.factory.annotation.Autowired:依赖冲突

InvalidTestClassError:无效测试类异常(@Test 没打)

BuilderException: Error creating document instance 错误创建文档实例(业务逻辑层改写的该写的正常写,只是sql语句写在xml里)

TransientDataAccessResourceException:暂态数据访问异常

MethodInvocationProceedingJoinPoint cannot be cast to class:动态代理中 ROUND语句有问题

SQLException: Access denied for user 'root'@'localhost' (using password:
YES)(解决:SpringConfig 配置中的 root密码不对)

返回给前端的json语句中文全是 问号 ? 解决方式: @RequestMapping(value = "/user",produces = "text/plain;charset=utf-8"

produces = "text/plain;charset=utf-8"是设置返回数据格式为文本格式

但是@ResponseBody设置返回数据格式为json字符串格式;会报错.

IllegalStateException[非法状态异常]::No primary or single unique constructor found for interface:检查是否语句是否错误(如data : date)

java:无法访问org.springframework.web.bind.annotation.RequestMapping

  错误的类文件: /D:/develop/WebSoft/apache-maven-3.6.1/mvn_repo/org/springframework/spring-web/6.0.11/spring-web-6.0.11.jar!/org/springframework/web/bind/annotation/RequestMapping.class类文件具有错误的版本 61.0, 应为 55.0

请删除该文件或确保该文件位于正确的类路径子目录中。

(解决 : 依赖问题) 见本文件夹内text ;

Identify and stop the process that's listening on port 8080 or configure this application to listen on another port.(spring boot的端口号冲突,在配置中更换端口号,或者停掉一个端口号)

Application run failed: (大概是配置文件没写)

UserConfig(username=null, password=null, addressList=null): 配置文件yaml空格不够 , 优先级应该置顶

MysqlDataTruncation: 先根据findById得到对应的修改对象;(还要数据库与插入的对象属性一一对应);

BindingException:解决::( Parameter 'userName' not found 对应参数的属性需要被实体类对象点出来)

SQLIntegrityConstraintViolationException: 更新没有where 条件

Ambiguous handler methods mapped for : 操作重复,删除单量的那个操作

getWriter() has already been called for this response : 清浏览器缓存

密码跟用户名为传入值为null,但不报错,且在登录校验之后,看一下控制层传参;

Initialization of bean failed;org/aspectj/lang/annotation/Pointcut :: 没有对应的切点以及依赖

### @Mapper 注解报错的原因分析 @Mapper 注解主要用于标记 MyBatis 的 Mapper 接口,使其能够被 Spring 容器识别并注册为 Bean。如果出现报错情况,通常可能由以下几个方面引起: 1. **缺少必要的依赖** 如果项目中未正确引入 `mybatis-spring-boot-starter` 依赖,则可能导致无法正常加载 MyBatis 功能模块,从而引发 @Mapper 注解失效的问题[^1]。 2. **配置文件缺失或错误** 在 Spring Boot 中集成 MyBatis 时,需要确保数据库连接等相关配置已正确设置于 `application.properties` 或 `application.yml` 文件中。若配置不全或者有误,也可能影响到 MyBatis 的初始化过程。 3. **扫描路径问题** 使用单独的 @Mapper 注解时,默认情况下每个 Mapper 接口都需要手动加上该注解才能让其成为 Spring 管理下的组件。另一种方法是通过全局定义的方式即利用 @MapperScan 来指定整个包下所有的 mapper 类都会自动装配进入 IOC 容器之中[^2]。 4. **版本兼容性冲突** 不同版本之间可能存在一定的差异性和潜在矛盾之处,比如某些旧版插件与新版框架间存在不适配现象,这同样会造成异常状况发生[^3]。 --- ### 解决方案 #### 方法一:确认并添加所需依赖 确保 pom.xml 文件中有如下所示的相关依赖项: ```xml <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>2.2.0</version> </dependency> ``` #### 方法二:检查 application 配置文件 以下是基于 properties 和 yml 格式的样例配置片段供参考: - 对于 `.properties` 用户可以这样设定参数: ```properties spring.datasource.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC spring.datasource.username=root spring.datasource.password=password spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver mybatis.mapper-locations=classpath:mapper/*.xml ``` - 而采用 `.yml` 则可按此结构书写: ```yaml spring: datasource: url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC username: root password: password driver-class-name: com.mysql.cj.jdbc.Driver mybatis: mapper-locations: classpath:mapper/*.xml ``` #### 方法三:合理运用 @Mapper 及 @MapperScan 注解 当仅需针对单个 Mapper 接口做处理时可以直接在其上声明 @Mapper; 而面对多个 Mapper 存在于同一目录及其子级的情况推荐使用 @MapperScan 进行批量操作,例如在启动类上方加入类似下面这样的代码即可完成统一管理: ```java @SpringBootApplication @MapperScan("com.example.demo.mapper") // 替换为自己项目的实际路径 public class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } } ``` #### 方法四:排查版本匹配度 仔细核对自己所使用的各个库之间的相互关系表,必要时候调整至官方文档建议组合形式之下运行测试验证效果如何改善现有困境状态。 --- ### 总结说明 上述四种途径均是从不同角度出发去定位解决问题所在,并给出相应对策措施加以应对。具体实施过程中可根据实际情况灵活选用其中一种或是多种联合起来共同作用达到最终目的——成功消除因 @Mapper 导致的各种错误提示信息恢复正常功能运作模式。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值