对于@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. 原生JavaScript实现jQuery的hasClass,removeClass,addClass,toggleClass

    介绍: 1.hasClass:判断DOM元素是否存在类. 2.addClass:为的DOM元素添加类. 3.removeClass:删除DOM元素的类. 4.toggleClass:如果DOM元素存在 ...

  2. [BZOJ1070][SCOI2007]修车 费用流

    1070: [SCOI2007]修车 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 6209  Solved: 2641[Submit][Status] ...

  3. MVC5下的switchbutton

    最近想提高代码生成的时候,是否选择显示样式好看些,所以想到了SwitchButton. 但是碰到个问题是,添加页面的这个初始值,需要写成true或者false 包括修改页面做个判断的话,渲染的做法也是 ...

  4. vi / vim 设置

    一.vi下方向键输入后,出现ABCD,解决方法: 在vi中输入:set nocp 按回车即可. 二.设置TAB缩进4个空格: 为了vim更好的支持python写代码,修改tab默认4个空格有两种设置方 ...

  5. (2)C#工具箱-公共控件2

    1.MaskedTextBox 限制填写数据格式的文本框 2.MonthCalendar 用法和DateTimePicker相同 日历 3.NotifIcon (1)添加此控件后,此界面运行时会弹出用 ...

  6. (9)oracle 表的基本查询

    转到进阶查询 查看表的结构 desc  表名; desc student; 查看整张表的数据 select * from 表名; //查整张表很耗时间 select* from student; 查看 ...

  7. Code+ B 汀博尔【二分答案】

    时间限制:C/C++ 1秒,其他语言2秒空间限制:C/C++ 262144K,其他语言524288K64bit IO Format: %lld 题目描述 有 n 棵树,初始时每棵树的高度为 Hi,第 ...

  8. 使用after伪类,配合IE的zoom或者overflow清除浮动

    用after伪类实现,兼容多种浏览器:.clearfix:after {content:"."; display:block; height:0; clear:both; visi ...

  9. Requirement Analysis

    BRD:Business Requirements Document,商业需求文档.这是产品声明周期中最早的问的文档,再早就应该是脑中的构思了,其内容涉及市场分析,销售策略,盈利预测等,通常是和老大们 ...

  10. [xsy2579]counting

    $\newcommand{\align}[1]{\begin{align*}#1\end{align*}}$题意:对于一个字符串$s$,定义$C(s)$为$s$中(出现次数最多的字母)出现的次数,问长 ...