添加事务后 org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type available

今天遇到了一个奇怪的问题   在没添加事务之前  所有的代码都是好的 , 当我添加了事务之后, 代码报错

org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type available

ApplicationContext:

<!-- 配置事务 -->
 <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  <property name="dataSource" ref="dataSource"></property>
 </bean>
 
<!-- 开启事务注解注入 -->
 <tx:annotation-driven transaction-manager="transactionManager"/>

BookShopServiceImpl

 @Transactional
 @Override
 public void purchase(String isbn, String username) {
//  1.获取书的单价
  int price = bookShopDao.findBookPriceByIsbn(isbn);
//  2.获取书的库存
  bookShopDao.updateBookStock(isbn);
//  3.更新用户信息
  bookShopDao.updateAccount(username, price);
 }

BookShopDaotest:

红色部分为添加的代码  , 然后机器认为有两个BookShopServiceImpl 类型的文件,但事实上只有一个。

bookShopDao = context.getBean(BookShopDaoImpl.class);
  bookShopService = (BookShopService) context.getBean("bookShopService");

之前是使用的是:

getBean(Class<BookShopDaoImpl> requiredType)

现在使用的是:

getBean(String name) throws BeansException最后在BookShopDao 中重新进行了Bean的获取  换了一种方式  用name的方式获取  而不是使用Class的形式

这样子机器就认识了。

还是需要自己去多学习下Spring的内部知识

时间: 2024-07-30 03:05:52

添加事务后 org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type available的相关文章

org.springframework.beans.factory.NoSuchBeanDefinitionException:No qualifying bean of type &#39;xxx &#39;available

搭了一个简单的SSM项目,启动报错: org.springframework.beans.factory.NoSuchBeanDefinitionException:No qualifying bean of type 'com.xxx.ssmdemo.service.IUserService' available: expected at least 1 bean which qualifies as autowire candidate.Dependency annotations: {@o

spring Boot异步操作报错误: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type &#39;com.self.spring.springboot.Jeep&#39; available

我也是最近开始学习Spring Boot,在执行异步操作的时候总是汇报如下的错误: Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.self.spring.springboot.Jeep' available at org.springframework.beans.factory.sup

org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [dx.service.ItemService] found for dependency

在整合ssm框架,测试service层的时候报错 Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [dx.service.ItemService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dep

springboot 报错 org.springframework.beans.factory.NoSuchBeanDefinitionException:No qualifying bean of type &#39;com.example.service.HrService&#39; available: 有没有大佬出个主意,我找了一天,刚入门springboot

话不多说先上图,这是启动类的配置,这里配置了@ComponentScan("我的mapper的接口") 接下来是我的项目结构截图 然后是service 的截图,我在这里加了注解@Service 最后我在测试类里面 的截图 最后附上我的maven的pom 我开始怀疑是这个配置的有问题了 <?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.a

org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

问题描述 org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'xxxxx.UserService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factor

org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.oskyhang.gbd.service.UserService] found for dependency: expected at least 1 bean which qualifies as aut

spring中一个符号的错误居然让我浪费了四五个小时才找出来,不得不给自己了两个耳光.. 由于新建项目与原来项目的目录结构有所不同,copy过来的配置文件,有些地方修改的不彻底,导致spring扫描注解的时候,扫描不到,不能注入bean,导致运行出错.一个马虎浪费了这么多时间,符号这种问题也往往最容易忽视的.<context:component-scan base-package="com.oskyhang.*.service"/> <context:componen

出现org.springframework.beans.factory.NoSuchBeanDefinitionException 的解决思路

Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private cn.itcast.crm.service.BaseDictService cn.itcast.crm.controller.CustomerController.baseDictService; nested exception is org.springframework.beans.fac

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException

1.错误描写叙述 usage: java org.apache.catalina.startup.Catalina [ -config {pathname} ] [ -nonaming ] { -help | start | stop } 2014-7-13 18:02:58 org.apache.catalina.core.AprLifecycleListener init 信息: Loaded APR based Apache Tomcat Native library 1.1.29 usi

nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException

You should autowire interface AbstractManager instead of class MailManager. If you have different implemetations of AbstractManager you can write @Component("mailService") and then @Autowired @Qualifier("mailService") combination to au