현재 Java Spring Boot Application을 Kotlin으로 다시 작성하려고합니다. @Service
으로 주석이 달린 모든 클래스에서 종속성 삽입이 올바르게 작동하지 않는 문제가 발생했습니다 (모든 인스턴스는 null
). 다음은 예입니다 자바에서 같은 일을스프링 부트 @ @Service의 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;
}
내가 코 틀린 모든 것을에서 @Component
와 구성 요소에 주석을하면 잘 작동 :
@Component
open class UserServiceController @Autowired constructor(val dsl: DSLContext, val teamService: TeamService) {
//dsl and teamService are injected properly
}
구글 Kotlin과 @Autowired
에 대한 여러 가지 접근 방식을 제공했지만 모두 동일한 결과를 가져 왔습니다. NullPointerException
Kotlin과 Java의 차이점을 알고 싶습니다. 어떻게 해결할 수 있습니까?
val을 var로 변경해 보셨습니까? –
[스프링 프록시 클래스 및 Kotlin의 [null 포인터 예외]의 가능한 복제본 (http://stackoverflow.com/questions/37431817/null-pointer-exception-in-spring-proxy-class-and-kotlin) – miensol
예 둘 다 시도했다. – Deutro