SpringBoot启动加载Mybatis时提示BeanPostProcessorChecker卡住

在SpringBoot应用启动时遇到BeanPostProcessorChecker阶段卡住的问题,原因是Mybatis配置中parameterType或resultMap的类型无法正确识别,导致启动失败。解决方法是确保所有涉及到的类路径都能被正确解析。
摘要由CSDN通过智能技术生成

BeanPostProcessorChecker

2020-11-18 15:13:56.863  INFO 29680 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'mybatis-org.mybatis.spring.boot.autoconfigure.MybatisProperties' of type [org.mybatis.spring.boot.autoconfigure.MybatisProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Spring Boot中使用MyBatis需要进行以下步骤: 1. 在pom.xml文件中添加MyBatisMyBatis-Spring的依赖: ``` <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.5.6</version> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>2.1.4</version> </dependency> ``` 2. 配置数据源(DataSource)和MyBatis的SqlSessionFactory: ``` @Configuration @MapperScan("com.example.mapper") // 扫描Mapper接口 public class MybatisConfig { @Bean @ConfigurationProperties(prefix = "spring.datasource") public DataSource dataSource() { return new DruidDataSource(); // 需要引入Druid的依赖 } @Bean public SqlSessionFactoryBean sqlSessionFactoryBean() throws Exception { SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean(); sqlSessionFactoryBean.setDataSource(dataSource()); return sqlSessionFactoryBean; } } ``` 3. 编写Mapper接口和对应的Mapper XML文件: ``` // UserMapper.java @Mapper public interface UserMapper { User findById(Long id); } // UserMapper.xml <mapper namespace="com.example.mapper.UserMapper"> <select id="findById" parameterType="long" resultType="com.example.model.User"> SELECT * FROM user WHERE id = #{id} </select> </mapper> ``` 4. 在Service中使用Mapper: ``` @Service public class UserServiceImpl implements UserService { @Autowired private UserMapper userMapper; @Override public User findById(Long id) { return userMapper.findById(id); } } ``` 以上就是在Spring Boot中使用MyBatis的基本步骤。需要注意的是,MyBatis的Mapper接口需要加上@Mapper注解,或在配置类中使用@MapperScan注解指定Mapper接口所在的包。同,也可以使用MyBatis提供的注解来替代Mapper XML文件。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值