通用类型的自动装配不起作用 [Spring 4+]

Autowiring of generic types doesn't work [Spring 4+]

我正在使用 Spring 4.2.4.RELEASE.

进行一个项目

我听说过新特性 Spring 4(尤其是 autowiring of generic types),当下面的代码没有被编译时,我很困惑:

@Service
public interface AuthenticationService<T> { ... }

public class VKAuthenticationService implements AuthenticationService<VKToken> { ... }

@RestController
public class VKAuthenticationController {
   @Autowired
   private AuthenticationService<VKToken> service;
}

提前感谢您的帮助。

在您的 VKAuthenticationService

上也声明 @Service 怎么样?
@Service(name="myService")
public class VKAuthenticationService implements AuthenticationService<VKToken> { ... }

并使用@Autowired@Qualifier注入它

@RestController
public class VKAuthenticationController {
   @Autowired
   @Qualifier("myService")
   private AuthenticationService<VKToken> service;
}