对于@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. 通过OpenGL ES在iOS平台实践增强现实

    http://www.cnblogs.com/elvisyzhao/p/3398250.html 本文采用OpenGL ES 1固定渲染管线实现,目标为在设备拍摄到的现实世界中,绘制世界坐标轴,并根据 ...

  2. Object和Thread自带的原生方法

    Object类: 1) clone():创建并返回此对象的一个副本. 2) equals(obj):指示其对象是否与此对象“相等”. 3) finalize():当垃圾回收器确定不存在对该对象的更多引 ...

  3. resin启动问题

    启动resin时报错如下: Resin/4.0.28 can't restart -server 'app-0'. com.caucho.bam.RemoteConnectionFailedExcep ...

  4. Linux安转jdk

    1. 创建目录 > mkdir  /opt/java > cd /opt/java 2. 下载jdk压缩包到上述目录 jdk-8u162-linux-x64.tar.gz 3. 解压缩.建 ...

  5. -webkit-box-flex: 1;属性和 float 属性冲突造成元素看不见的BUG

    今天切图的时候发现了这个问题,样式是这样的: .check-btns-box .check-btn{float: left;-webkit-box-flex: 1;-moz-box-flex: 1;- ...

  6. bring to front 必须在右边的form上才生效。

  7. 使用函数方式生成UUID

    1.默认生成的UUID是有 “-” 分隔符的 例如: public static void main(String[] args){ String uuid = UUID.randomUUID().t ...

  8. CentOS7.0使用Yum安装Nginx

    安装Nginx yum install nginx 正常情况下必定是: 已加载插件:fastestmirror, langpacks base | 3.6 kB 00:00:00 docker-mai ...

  9. [BZOJ2084][Poi2010]Antisymmetry 二分+hash

    2084: [Poi2010]Antisymmetry Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 812  Solved: 503[Submit] ...

  10. Knockout 双向绑定的理解

    今天做了个需求就是上传图片,然后在代码中通过jQuery给一个标签赋值,经过前台的debug,发现这个值赋值成功了,但是提交到后台的请求里就没了,然后经历了一顿度娘,结果中发现了问题. 既然knock ...