Привет, ребята, я разрабатываю приложение с помощью Spring Boot, хотя у меня возникают некоторые проблемы при инициализации репозитория JPA в потоке, генерирующем следующую ошибку
Exception in thread "Thread-6" kotlin.UninitializedPropertyAccessException: lateinit property contactTypeAudioPathRepository has not been initialized
at com.sopristec.sa_tas.controllers.ProvisioningController$createAudioWithAsync$executeP$1.run(ProvisioningController.kt:96)
at java.lang.Thread.run(Thread.java:748)
Я использую @Autowired для его запуска и Вот как выглядит функция
@Autowired
private lateinit var contactTypeAudioPathRepository: ContactTypeAudioPathRepository
fun createAudioWithAsync(menuChoice: String, presentation: String) {
val executeP = Thread{
val message = "Press $menuChoice to save this phone number as $presentation. Or " +
"Press 9 to save as work number"
val commandVoice = mutableListOf<String>("python","pythonScript/main.py",message);
val buildAudio = ProcessBuilder(commandVoice).start()
val getPath = buildAudio.inputStream.bufferedReader().use { it.readText() }
if(getPath.isEmpty()){
println("A python script failed")
}
println(getPath.replace("\n","").replace("att_sas_pyttsx3/",""))
val fileName = getPath.replace("\n","")
contactTypeAudioPathRepository.save(ContactTypeAudioPath(0,fileName))
// Genera error --> contactTypeAudioPathRepository.add("mediaLink").subscribe()
}.start()
// executeP.start();
//contactTypeAudioPathRepository.add("mediaLink").subscribe()
}
Это хранилище, как вы можете видеть, с помощью CrudRepository JPA
@Repository
interface ContactTypeAudioPathRepository : CrudRepository<ContactTypeAudioPath,Int> {
}
Спасибо