Neo4J存储库没有连线到处

我已经定义了一个Neo4j存储库(代码在Kotlin中,但它非常接近Java):

@Repository interface UserRepository : GraphRepository<User> { fun findByEmail(email: String): User? @Query("match (n:User)-[:IS_AUTH]->(:Permission {name: {0}}) where id(n) = {1} return n") fun authorizedUser(permission: String, userId: Long): User? } 

在一个控制器中,我写了:

 @Controller @RequestMapping("/company") open class CreateCompanyController { @Autowired private lateinit var userRepo: UserRepository @RequestMapping(method = arrayOf(RequestMethod.POST)) @ResponseBody fun createCompany(@RequestParam(value = "name", required = true) name: String, @RequestParam(value = "siret", required = true) siret: Long) : ResponseEntity<String> { val connectedUser = SecurityContextHolder.getContext().authentication.principal as User val testUser = userRepo.findByEmail("test@company.com") if (!PermissionManager().hasAuthorizationFor(PermissionManager.ADMIN_ALL, connectedUser)) return ResponseEntity("You're not authorized to create a company", HttpStatus.FORBIDDEN) return ResponseEntity(HttpStatus.OK) } } 

在上面的代码中, userRepo属性设置的很好(又名。它的值不为空)。

我想在一个自定义的服务中有这个UserRepository。 所以,我已经编码:

 @Service open class PermissionManager { companion object { val ADMIN_ALL = "ADMIN_ALL" } @Autowired private lateinit var userRepo: UserRepository fun hasAuthorizationFor(permissionName: String, user: User): Boolean { return userRepo.authorizedUser(permissionName, user.id!!) != null } } 

但在这种情况下, userRepo属性不会被初始化。

我已经写了PersistenceContext类为:

 @Configuration @ComponentScan("persistence") @EnableNeo4jRepositories("persistence.repositories") @EnableTransactionManagement open class PersistenceContext : Neo4jConfiguration() { @Bean override fun getSessionFactory(): SessionFactory { return SessionFactory("persistence.domain") } @Bean @Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS) open override fun getSession(): Session { return super.getSession() } } 

我不明白的是为什么在我的控制器中设置userRepo,而不是在我的服务?