Spring loading interface

I am wondering if spring is loading an interface declared as an @autowired attribute of an @autowired class, without annotating the interface as a @component .

Let me describe my problem a little more: I have both the interface and its implementation class have the same name, but they are in different packages. I annotated the implementation as @Component("myImplementation") . but I get an exception that says:

 conflicts with existing, non-compatible bean definition of same name and class 

I am thinking of excluding interfaces from <context:component-scan , what do you think?

PS: my interface is not @Component annotated, the application works fine on developmentpement environement, I get an error after obfuscation Proguard

+2
spring java-ee
Apr 25 2018-12-25T00:
source share
3 answers

Annotating your implementation with @Component and not annotating your interface is usually the right way to customize. Spring automatic wiring will look for a managed bean of the appropriate type, and your implementation will match the field typed in by the interface. If your interface is not annotated using @Component or any Spring stereotype annotation, it should not be loaded into the context during component scanning. This way you shouldn't have a problem if the interface and implementation have the same class name.

Are you sure you did not try to annotate the interface? Are you sure that you do not have another class in another place of your project that also has the same name as the interface and its implementation?

+1
Apr 25 '12 at 19:29
source share

Your proguard.conf should contain:

 ## ... 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 contains more detailed answers.

+1
Aug 28 '12 at 21:41
source share

Well, I think moving interfaces in different packages will work, because you create a link to an interface object and the corresponding beans implementation will automatically connect to these object links. But you must follow naming conventions. It would be a problem in differentiating interfaces and implementation classes, since the names were the same. Follow standards for example

 interface SomeInterface { //.... } 

for the implementation class SomeInterface

 class SomeInterfaceImpl implements SomeInterface { // implementation.... } 
0
Apr 25 2018-12-25T00:
source share



All Articles