I have a service with a bunch of @Autowired services. When I changed one of the methods to be @Transactional, it prevented all of the @Autowired as they are all null.
Example:
@Service
open class UserService {
@Autowired
private val userRepository : UserRepository? = null
@Autowired
private val emailService : EmailService? = null
@Transactional
@Throws(EmailConflictException::class)
open fun insert(newUser: User, context : RequestContext) {
if(!isEmailAvailable(newUser.email)) throw EmailConflictException()
val user = userRepository!!.insert(newUser, context.org.id)
emailService!!.send(userEmailFactory!!.getInviteEmail(user))
}
}
Both emailService and userRepository are null during runtime upon calling insert. If I removed the @Transactional from the insert method then both emailService and userRepository are defined during runtime.
Why is this happening? How do I fix it