我想知道 spring 在声明为 @autowired
时是否加载接口(interface)实现类的属性,而无需将接口(interface)注释为 a @component
.
让我再描述一下我的问题:
我有一个接口(interface)及其实现类具有相同的名称,但它们驻留在不同的包中。我将实现注释为 @Component("myImplementation")
。
但我最终遇到了一个异常(exception):
conflicts with existing, non-compatible bean definition of same name and class
我正在考虑从 <context:component-scan
中排除接口(interface),你觉得怎么样?
PS:我的界面不是 @Component
注解,应用程序在开发环境中运行得很好,我只在 Proguard 混淆后得到错误
最佳答案
您的proguard.conf应包含:
## ... preserve class annontation (Java EE 1.6 DI)
# Spring3
#-keep @org.springframework.stereotype.Service class *
-keep @org.springframework.stereotype.Controller class *
#-keep @org.springframework.stereotype.Component class *
#-keep @org.springframework.stereotype.Repository class *
proguard forums有更详细的答案。
关于Spring接口(interface)加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10318482/