• @Autowired @Transaction @Service同时出现。


    对于@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。

  • 相关阅读:
    Another mysql daemon already running with the same unix socket
    cloud maintenance of OpenNebula
    内核分析阅读笔记
    eucalyptus,openNebula云构建漫谈
    quotation
    Adress
    cos
    COS回应7大质疑
    linux内核地址mapping
    开源 免费 java CMS
  • 原文地址:https://www.cnblogs.com/flying607/p/4821306.html
Copyright © 2020-2023  润新知