I have the following structure:
public class StringFactory {
@Inject
private Instance<StringFormatter> formatterInstances;
@PostConstruct
public void init() {
for (AddressFormatter formatter : formatterInstances) {
System.out.println("String formater: " + formatter);
}
}
}
StringFormatter
interface StringFormatter {
String createFormattedString(final String x);
}
StringFormaterForKR
public class StringFormaterForKR implements StringFormatter {
@Override
public String createFormattedString(String x) {
return null;
}
DefaultStringFormater
public class DefaultStringFormater implements StringFormatter {
@Override
public String createFormattedString(String x) {
return null;
}
Test
public class Test() {
public static void main(String args[]) {
StringFactory factory = new StringFactory();
}
}
I don't understand why formatterInstances is null ? And I saw that the message from PostConstruct is never printed...
Do you have any explication for this ?