現在、私はKotlinでJava Spring Boot Applicationを書き直そうとしています。 @Service
で注釈が付けられているすべてのクラスで、依存関係注入が正しく機能していないという問題に遭遇しました(すべてのインスタンスはnull
です)。ここでは一例です:Javaで同じことを春のブート@AutowiredのKotlinは@サービスで常にnullです
@Service
@Transactional
open class UserServiceController @Autowired constructor(val dsl: DSLContext, val teamService: TeamService) {
//dsl and teamService are null in all methods
}
は何の問題もなく動作します。
@Service
@Transactional
public class UserServiceController
{
private DSLContext dsl;
private TeamService teamService;
@Autowired
public UserServiceController(DSLContext dsl,
TeamService teamService)
{
this.dsl = dsl;
this.teamService = teamService;
}
私はKotlinのすべてで@Component
を持つコンポーネントが正常に動作注釈を付ける場合:
@Component
open class UserServiceController @Autowired constructor(val dsl: DSLContext, val teamService: TeamService) {
//dsl and teamService are injected properly
}
グーグル私が試みたコットリーンと@Autowired
のための多くの異なるアプローチを提供しましたが、すべて同じ結果になりましたNullPointerException
私はKotlinとJavaの違いを知りたいのですが、どうすればこの問題を解決できますか?
valをvarに変更しようとしましたか? –
[SpringプロキシクラスとKotlinでのNull Pointer例外の可能な複製](http://stackoverflow.com/questions/37431817/null-pointer-exception-in-spring-proxy-class-and-kotlin) – miensol
はい私はすでに両方を試みた。 – Deutro