@Transactional+@Autowired出现的lateinit property xx has not been initialized错误
1 问题描述
用Kotlin编写Spring Boot,在业务层中使用@Transactional+@Autowired时出现如下错误:
lateinit property dao has not been initialized

出错代码如下:

2 解决办法
因为Kotlin类默认是final的,加上@Transactional后编译器提示需要open:

但是加上open后没用,因此把@Transactional去掉后发现不会报错:

因此怀疑是@Transactional的问题,因为需要在类上加上open,所以尝试性地在对应的方法上面也加上open:

问题得到解决。
3 原因
因为@Transactional实际上是通过反射获取Bean的注解信息,利用AOP实现的,而在Kotlin中使用AOP需要在类或方法上加上open。
@Transactional+@Autowired出现的lateinit property xx has not been initialized错误的更多相关文章
- JobStorage.Current property value has not been initialized. You must set it before using Hangfire Client or Server API.
JobStorage.Current property value has not been initialized. You must set it before using Hangfire Cl ...
- Bean property XX' is not writable or has an invalid setter method
刚刚搞spring.property注入时遇到这个问题,百度一下.非常多人说是命名或者get set方法不一致的问题,可是这个我是知道的.写的时候也注意到这些.所以应该不是这个问题.以为是xml头写的 ...
- Request failed with status code 500以及自引用循环Self referencing loop detected for property ‘xx‘ with type
错误Error: Request failed with status code 500 ,调试前端没问题,后端也没问题,还报错"连接超时" 在Network中找到错误Self r ...
- javascript异常cannot read property xx of null 的错误
一般报这种异常或者错误,是因为试图从null中再读一个属性导致的. 比如:var myAttr=myObj.data.Name; 假如这个时候myObj.data是null,那么再试图读取data的N ...
- React第一次渲染为何容易出现TypeError: Cannot read property 'XX' of undefined
此题可能大家会不屑一顾,哎,错误都给你怼脸上了你还不会嘛,其实大家有没有认真思考过这其中的原因.先上一张错误图,剩余的全靠编.没兴趣看图的老铁们可以拉到最底下直接看结论 错误: 代码: 其次,我再把 ...
- java.lang.IllegalStateException:Web app root system property already set to different value 错误原因及解决 Log4j
Log4j是Apache的一个开放源代码项目,通过使用Log4j,我们可以控制日志信息输送的目的地是控制台.文件.GUI组件.甚至是套接口 服务器.NT的事件记录器.UNIX Syslog守护进程等: ...
- Web app root system property already set to different value 错误原因及解决
http://yzxqml.iteye.com/blog/1761540 ——————————————————————————————————————————————————————————————— ...
- idea中 参数没有描述报错 @param XX tag description is missing错误,去除黄色警告
最近在使用idea开发工具,在方法备注中参数没有描述报错就会报一些黄色警告: @param XX tag description is missing,下面展示去除黄色警告的方法 File--sett ...
- TypeError: Cannot read property 'style' of null 错误解决
错误信息例如以下: JSP代码例如以下: <c:if test ="${not empty excelErrors}"> <div id="excelE ...
随机推荐
- MySQL的简单使用方法备忘
这只是一篇我的个人备忘录,写的是我常用的命令.具体可以参考"菜鸟教程" https://www.runoob.com/mysql/mysql-tutorial.html 登录(用户 ...
- Differences between Stack and Heap
本文转载自Differences between Stack and Heap Stack vs Heap So far we have seen how to declare basic type ...
- dev 控件获得所有的EFDEVGRID
//获得当前Grid DevExpress.XtraGrid.GridControlNavigator GCN2 = sender as DevExpress.XtraGrid.GridControl ...
- 深入剖析 ConcurrentHashMap
自建博客地址:https://bytelife.net,欢迎访问! 本文为博客自动同步文章,为了更好的阅读体验,建议您移步至我的博客 本文作者: Jeffrey 本文链接: https://bytel ...
- eclipse从接口快速跳转到实现类
1.只跳转到实现类上 按住Ctrl键,把鼠标的光标放在要跳转的接口上面,选择第二个 2.直接跳转大实现的方法上 按住Ctrl键,把鼠标的光标放在要跳转的方法上面,选择第二个 对比可以发现,操作都是一样 ...
- Maven 打包项目到私服 (deploy)
一.配置maven 在maven安装目录 /conf/setting.xml 中的servers下添加: 1 <servers> 2 <server> 3 <id> ...
- 判断app是否安装
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); intent.setData(Uri.fromPar ...
- 求幂&&快速幂&&位运算
1.普通的求幂方法: 时间复杂度为O(n),对于比较大的数在1s限时内可能会TLE int pow(int base,int p){ int ans=1; for(int i=1;i<=p;i+ ...
- YSU小吃街
贪心贪不过,暴力搜就完事了 注意不连通情况 #include<iostream> #include<sstream> #include<cstdio> #inclu ...
- Java-for循环打印九九乘法表
Java打印九九乘法表 public class forDemo04 { public static void main(String[] args) { //练习3:打印九九乘法表 /* 1*1=1 ...