0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Kotlin + Spring bootで @Service に @Transactional した時の @Autowired がnullになる時の対処方法

Posted at

Kotlin + Spring bootのサーバサイドKotlinで@Transactionalを付与したときに@Autowired がnullになってエラーが発生したときの対応方法です。

ここでの問題は、Kotlinではメソッドがデフォルトでfinalであるため、Springがクラスのプロキシを作成できないことです。

o.s.aop.framework.CglibAopProxy: Unable to proxy method [public final int org.mycompany.MyDAO.update(...

classとメソッドに「open」を追記することで問題が解決されます。

@Service
@Transactional  
open class MyDAO(val jdbcTemplate: JdbcTemplate) {

   open fun update(sql: String): Int {
       return jdbcTemplate.update(sql)
   }

} 

これで自分のシステムもうまく動きました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?