对于@Autowired,如果只写这些,肯定是根据类型自动装配这个没问题。

@Service

public class AcRoleServiceImpl implements AcRoleService{

  ......

}

这个bean生成后会兼有AcRoleServiceImpl 和AcRoleService两种类型,所以以下两种写法都可以成功装配。

@Autowired
private AcRoleServiceImpl acRoleService;

@Autowired
private AcRoleService acRoleService;

 

但是如果@Transaction出现在AcRoleService这个接口中,则只能使用以下方式

@Autowired
private AcRoleService acRoleService;

所以一旦有用到@Transaction一定要用上边这种方式(类型为接口类型)的自动装配。

否则会报错,具体原因只能猜测。

由于本人没有时间去深究,以下只是猜测内容,以备以后有空再来回头研究,请读者自行屏蔽

导致根据类型的自动装配失败的原因无非两种:找不到这种类型的bean或者找到了多个这种类型的bean。

排除出现两个以上AcRoleServiceImpl 类型的bean,那就是AcRoleServiceImpl 没有生成。

而只生成了AcRoleService。

于是可以断定:在扫描到@Transaction时会根据其接口和实现类生成一个类型为其接口类型的bean,而之后扫描到@Service时由于已经生成过了相同类型的bean则不再生成新的bean。

@Autowired @Transaction @Service同时出现。的更多相关文章

  1. @resource、@Autowired、@Service在一个接口多个实现类中的应用

    Spring在没有引入注解之前,传统的Spring做法是使用.xml文件来对bean进行注入,所有的内容都需要配置在.xml文件中,使配置和编程分离,却增加了可读性和复杂度. Spring注解将复杂的 ...

  2. Spring使用Quartz定时调度Job无法Autowired注入Service的解决方案

    1)自定义JobFactory,通过spring的AutowireCapableBeanFactory进行注入,例如: public class MyJobFactory extends  org.s ...

  3. Springboot在工具类(Util)中使用@Autowired注入Service

    1. 使用@Component注解标记工具类MailUtil: 2. 使用@Autowired注入我们需要的bean: 3. 在工具类中编写init()函数,并使用@PostConstruct注解标记 ...

  4. spring springboot websocket 不能注入( @Autowired ) service bean 报 null 错误

    spring 或 springboot 的 websocket 里面使用 @Autowired 注入 service 或 bean 时,报空指针异常,service 为 null(并不是不能被注入). ...

  5. Spring注解的使用和区别:@Component、@Service、@Repository、@Controller

    Spring 2.5 中除了提供 @Component 注释外,还定义了几个拥有特殊语义的注释,它们分别是:@Repository.@Service 和 @Controller.在目前的 Spring ...

  6. springboot 静态方法注入service

    p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; line-height: 16.0px; font: 14.0px Arial; color: #3f3f3f; bac ...

  7. Spring Boot @Autowired 没法自动注入的问题

    Application 启动类: @SpringBootApplication @EnableConfigurationProperties @ComponentScan(basePackages = ...

  8. SpringBoot在自定义类中调用service层等Spring其他层

    解决方案: 1.上代码 @Component public class ServerHandler extends IoHandlerAdapter { @Autowired protected He ...

  9. spring整合Jersey 无法注入service的问题

    现象: action中的@autowired注入service或dao失败,报空指针异常 原因: 造成该问题的原因是你并没有做好spring和jersey的整合工作,检查你的web.xml文件,jer ...

随机推荐

  1. cocos2d programming guide翻译(12)

    http://bbs.tairan.com/thread-807-1-1.html 导演缓冲信息支持cocos2d v0.99.4和更新的版本颜色缓冲这个默认的缓冲时RGB565.它是一个16位的缓冲 ...

  2. Profile 的翻译

    最近要翻译一个英文网站的单词,正宗的英文网站总是有很多单词让我烦恼,这就是其中一个. 特地转一篇文章,对我大有帮助. 计算机中常用的 Profile 该如何理解? 我认为 Profile 即可作名词又 ...

  3. 向PE文件中空白处添加代码

    // mem.cpp : 定义控制台应用程序的入口点. //PE文件从文件加载到内存,再从内存读取,然后存盘到文件 #include "stdafx.h" #include < ...

  4. vim的最最基本配置

    全部用户生效 /etc/vimrc 当前用户生效 ~/.vimr # 1.设置语法高亮syntax on # 2.显示行号 set nu # 3.设置换行自动缩进为4个空格 # 4.设置tab缩进为空 ...

  5. ORA-01940: cannot drop a user that is currently connected

    https://www.cnblogs.com/lwlxqlccc/p/8694696.html

  6. [BZOJ2223][BZOJ3524][Poi2014]Couriers 主席树

    3524: [Poi2014]Couriers Time Limit: 20 Sec  Memory Limit: 256 MBSubmit: 2436  Solved: 960[Submit][St ...

  7. (1)请求web

    用来测试api的例子 <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> ...

  8. HDU 2639 Bone Collector II【01背包 + 第K大价值】

    The title of this problem is familiar,isn't it?yeah,if you had took part in the "Rookie Cup&quo ...

  9. 状压DP【p1879】[USACO06NOV]玉米田Corn Fields

    Description 农场主John新买了一块长方形的新牧场,这块牧场被划分成M行N列(1 ≤ M ≤ 12; 1 ≤ N ≤ 12),每一格都是一块正方形的土地.John打算在牧场上的某几格里种上 ...

  10. Editing 2011-2012 ACM-ICPC Northeastern European Regional Contest (NEERC 11)

    NEERC 11 *wiki链接[[https://acm.ecnu.edu.cn/wiki/index.php?title=2011-2012_ACM-ICPC_Northeastern_Europ ...