I have TaskService interface and TaskServiceImpl class:
@Service
class TaskServiceImpl(val taskRepository: TaskRepository,
val userRepository: UserRepository,
val taskEntityConverter: TaskEntityConverter,
val taskCreateResponseConverter: TaskCreateResponseConverter,
val taskResponseConverter: TaskResponseConverter,
@Resource(name = “requestScopedUser”) val currentUserInfo: UserInfo) : TaskService {
// … other methods
override fun getTaskPage(pageable: Pageable): Page<TaskResponse> {
return taskRepository.findAllByUserId(currentUserInfo.userId!!, pageable)
.map { taskResponseConverter.apply(it) }
}
// …other methods
}
RequestScopedUserProvider class:
@Configuration
class RequestScopedUserProvider(private var userRepository: UserRepository) {
@RequestScope
@Bean
fun requestScopedUser(): UserInfo {
val authentication = SecurityContextHolder.getContext().authentication
val email = authentication.name
val user = userRepository.findByEmail(email) ?: throw ResourceNotFoundException("User not found")
return UserInfo(user.id)
}
}
With the help of this class i want to get userId from jwt token which comes with request and use it in my getTaskPage(pageable: Pageable) method. But when i log some messages in this class i can see that it correctly extracts userId but in service class it comes null and i can’t figure out why.