@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。
@Autowired @Transaction @Service同时出现。的更多相关文章
- @resource、@Autowired、@Service在一个接口多个实现类中的应用
Spring在没有引入注解之前,传统的Spring做法是使用.xml文件来对bean进行注入,所有的内容都需要配置在.xml文件中,使配置和编程分离,却增加了可读性和复杂度. Spring注解将复杂的 ...
- Spring使用Quartz定时调度Job无法Autowired注入Service的解决方案
1)自定义JobFactory,通过spring的AutowireCapableBeanFactory进行注入,例如: public class MyJobFactory extends org.s ...
- Springboot在工具类(Util)中使用@Autowired注入Service
1. 使用@Component注解标记工具类MailUtil: 2. 使用@Autowired注入我们需要的bean: 3. 在工具类中编写init()函数,并使用@PostConstruct注解标记 ...
- spring springboot websocket 不能注入( @Autowired ) service bean 报 null 错误
spring 或 springboot 的 websocket 里面使用 @Autowired 注入 service 或 bean 时,报空指针异常,service 为 null(并不是不能被注入). ...
- Spring注解的使用和区别:@Component、@Service、@Repository、@Controller
Spring 2.5 中除了提供 @Component 注释外,还定义了几个拥有特殊语义的注释,它们分别是:@Repository.@Service 和 @Controller.在目前的 Spring ...
- springboot 静态方法注入service
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; line-height: 16.0px; font: 14.0px Arial; color: #3f3f3f; bac ...
- Spring Boot @Autowired 没法自动注入的问题
Application 启动类: @SpringBootApplication @EnableConfigurationProperties @ComponentScan(basePackages = ...
- SpringBoot在自定义类中调用service层等Spring其他层
解决方案: 1.上代码 @Component public class ServerHandler extends IoHandlerAdapter { @Autowired protected He ...
- spring整合Jersey 无法注入service的问题
现象: action中的@autowired注入service或dao失败,报空指针异常 原因: 造成该问题的原因是你并没有做好spring和jersey的整合工作,检查你的web.xml文件,jer ...
随机推荐
- (wifi)wifi移植之命令行调试driver和supplicant
前言 小弟从事android wifi framework部分开发已经有一年的时间了,虽然感觉什么都没有学习到,但是回想起刚接手android wifi时候的那份无知,其实肚子里面还是有点东西的,本着 ...
- git使用过程中遇到的错误
1.使用git add "login.py" 然后git commit -m "add url"的时候报错.分支newtype也是存在的 nothing to ...
- 传输网页数据的json与xml
#转载请留言联系 1.json json是数据格式,经常用于在网络中,不同平台或者不同语言中进行数据的传输.json的文件后缀就是 .json.当然,也可以把json直接写在js文件中. json储存 ...
- snmp 学习
SNMP:“简单网络管理协议”,用于网络管理的协议.SNMP用于网络设备的管理.SNMP的工作方式:管理员需要向设备获取数据,所以SNMP提供了“读”操作:管理员需要向设备执行设置操作,所以SNMP提 ...
- Hadoop打包成jar包在集群上运行时出现的各种问题以及解决方案
之前将eclipse下编好的mapreduce代码放到集群上面跑,发现速度很慢,namenode节点的cpu和内存使用率很低,datanode节点基本上处于没有运行的状态,然后通过查看hadoop-e ...
- HDU 1203 【01背包/小数/概率DP】
I NEED A OFFER! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tot ...
- Python与正则表达式[0] -> re 模块的正则表达式匹配
正则表达式 / Regular Expression 目录 正则表达式模式 re 模块简介 使用正则表达式进行匹配 正则表达式RE(Regular Expression, Regexp, Regex) ...
- FZU-2214 Knapsack problem(DP使用)
Problem 2214 Knapsack problem Accept: 863 Submit: 3347Time Limit: 3000 mSec Memory Limit : 327 ...
- StringBuffer 清空
几种方法: 方法1: 1 2 3 4 StringBuffer my_StringBuffer = new StringBuffer(); my_StringBuffer.append('hellow ...
- 第一讲work(axe)
1,Dao package com.songyan.Dao; public interface Axe { public void chop(); } package com.songyan.Dao; ...