Analog MEF (.NET) for Java

I am very used to this clean syntax using MEF in .NET.

[Export(typeof(ISomething))] public class Something : ISomething { } 

Is there an analogy to annotations in Java? (and corresponding structure). Any dependency injection containers should be well compatible with?

+4
source share
2 answers

There are several IoC containers available in Java. It seems to me that Spring is with an IoC container and Google Guice .

I mainly worked with Spring IoC and it is very pleasant to work with it.

Here 's another good Spring IoC tutorial.

+3
source

From what I could find up to the point , I can use Google Guice with its annotations. There (in GG ) they define the default interface executor, and do not export the implementation (as in MEF). For instance.

 @ImplementedBy(Something.class) public interface ISomething { ... } public class Something implements ISomething { ... } 

Injection of constructor parameters, etc. also possible from the documentation.

+2
source

Source: https://habr.com/ru/post/1435543/


All Articles