SpringBoot整合Mybatis创建bean失败,============================ CONDITIONS EVALUATION REPORT ==============

​​在这里插入图片描述这有可能不只是sevice层自动装配bean失败,可能dao层也装配失败!

一.先看控制台报错信息


============================
CONDITIONS EVALUATION REPORT
============================


Positive matches:
-----------------

   AopAutoConfiguration matched:
      - @ConditionalOnProperty (spring.aop.auto=true) matched (OnPropertyCondition)

   AopAutoConfiguration.ClassProxyingConfiguration matched:
      - @ConditionalOnMissingClass did not find unwanted class 'org.aspectj.weaver.Advice' (OnClassCondition)
      - @ConditionalOnProperty (spring.aop.proxy-target-class=true) matched (OnPropertyCondition)

   DataSourceAutoConfiguration matched:
      - @ConditionalOnClass found required classes 'javax.sql.DataSource', 'org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType' (OnClassCondition)
      - @ConditionalOnMissingBean (types: io.r2dbc.spi.ConnectionFactory; SearchStrategy: all) did not find any beans (OnBeanCondition)

   DataSourceAutoConfiguration.PooledDataSourceConfiguration matched:
      - AnyNestedCondition 1 matched 1 did not; NestedCondition on DataSourceAutoConfiguration.PooledDataSourceCondition.PooledDataSourceAvailable PooledDataSource found supported DataSource; NestedCondition on DataSourceAutoConfiguration.PooledDataSourceCondition.ExplicitType @ConditionalOnProperty (spring.datasource.type) did not find property 'type' (DataSourceAutoConfiguration.PooledDataSourceCondition)
      - @ConditionalOnMissingBean (types: javax.sql.DataSource,javax.sql.XADataSource; SearchStrategy: all) did not find any beans (OnBeanCondition)

   DataSourceConfiguration.Hikari matched:
      - @ConditionalOnClass found required class 'com.zaxxer.hikari.HikariDataSource' (OnClassCondition)
      - @ConditionalOnProperty (spring.datasource.type=com.zaxxer.hikari.HikariDataSource) matched (OnPropertyCondition)
      - @ConditionalOnMissingBean (types: javax.sql.DataSource; SearchStrategy: all) did not find any beans (OnBeanCondition)

   DataSourceInitializationConfiguration matched:
      - @ConditionalOnClass found required class 'org.springframework.jdbc.datasource.init.DatabasePopulator' (OnClassCondition)
      - @ConditionalOnSingleCandidate 
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
SpringBoot整合Mybatis和Redis的原理主要包括以下几个方面: 1. SpringBoot整合MybatisSpringBoot提供了Mybatis的自动配置功能,只需要在pom.xml中引入相关的依赖,配置好数据源,就可以使用Mybatis进行数据库操作。 2. SpringBoot整合Redis:SpringBoot提供了对Redis的支持,只需要在pom.xml中引入相关的依赖,配置好Redis的连接信息,就可以使用Redis进行缓存操作。 3. 整合过程:在整合过程中,需要将Mybatis的查询结果进行序列化,存入Redis缓存中,同时在查询数据时,先从Redis缓存中获取数据,如果获取不到再从数据库中获取数据,并将结果存入Redis缓存中。 具体实现可以参考以下步骤: 1. 配置数据源和Mybatis:在application.properties文件中配置数据源和Mybatis相关信息,例如: ``` spring.datasource.url=jdbc:mysql://localhost:3306/test?useSSL=false spring.datasource.username=root spring.datasource.password=123456 mybatis.mapper-locations=classpath:mapper/*.xml ``` 2. 配置Redis:在application.properties文件中配置Redis相关信息,例如: ``` spring.redis.host=localhost spring.redis.port=6379 spring.redis.password= spring.redis.database=0 ``` 3. 配置RedisTemplate:使用RedisTemplate进行Redis操作,可以在配置类中进行配置,例如: ``` @Configuration public class RedisConfig { @Autowired private RedisConnectionFactory redisConnectionFactory; @Bean public RedisTemplate<String, Object> redisTemplate() { RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>(); redisTemplate.setConnectionFactory(redisConnectionFactory); redisTemplate.setKeySerializer(new StringRedisSerializer()); redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer()); return redisTemplate; } } ``` 4. 编写缓存操作代码:在查询数据时,先从Redis缓存中获取数据,如果获取不到再从数据库中获取数据,并将结果存入Redis缓存中,例如: ``` @Service public class UserServiceImpl implements UserService { private static final String REDIS_KEY_PREFIX = "user:"; @Autowired private UserMapper userMapper; @Autowired private RedisTemplate<String, Object> redisTemplate; @Override public User getUserById(Integer id) { String key = REDIS_KEY_PREFIX + id; User user = (User) redisTemplate.opsForValue().get(key); if (user == null) { user = userMapper.getUserById(id); if (user != null) { redisTemplate.opsForValue().set(key, user); } } return user; } } ``` 以上就是SpringBoot整合Mybatis和Redis的原理及实现步骤。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值