一、问题
新的项目试用kotlin,在业务类上添加@Transactional,并使用@Autowired引用mapper、配置类等,测试执行时报lateinit property prop has not been initialized
二、程序样例(报错的)
/**
* @author zc
* @date 2024/06/06 16:39
* @desc 资源采集
*/
@Service
@Transactional
open class ResourceCollectService {
@Autowired
private lateinit var cmReadMapper: CmReadMapper
@Autowired
private lateinit var exportUtil: ExportUtil
@Autowired
private lateinit var prop: Prop
/**
* Execute
* 资源采集
* @param cmEnums
*/
fun execute(cmEnum: CmEnum, channelSftp: ChannelSftp) {
val timeFormatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss")
val createTime = timeFormatter.format(LocalDateTime.now().plusHours(-1))
val collectTime = timeFormatter.format(LocalDateTime.now())
val dateTimeFormatter = DateTimeFormatter.ofPattern("yyyyMMdd")
//统计前一天数据
val date = dateTimeFormatter.format(LocalDate.now().plusDays(-1))
when (cmEnum) {
CmEnum.数据中心 -> {
val dataCenters = mutableListOf<CmDataCenter>()
dataCenters.add(CmDataCenter())
if (!CollectionUtils.isEmpty(dataCenters)) {
val fileName = CmEnum.数据中心.value.uppercase() + "_" + createTime + "_" + collectTime + ".gz"
val localFilePath = prop.source + DataEnum.resource + "/" + dat