Details
-
Type: Bug
-
Status: Resolved
-
Priority: Major
-
Resolution: Fixed
-
Affects Version/s: 3.0
-
Fix Version/s: 3.0
-
Component/s: PicoContainer (Java)
-
Labels:None
-
Testcase included:yes
-
Number of attachments :
Description
Discussed here:
http://article.gmane.org/gmane.comp.java.picocontainer.user/1293/match=inject
and other places in the mailing list.
@Test public void testComponentCanUseConstructorAndAtInjectWithoutAnInitMethod() { final MutablePicoContainer pico = new DefaultPicoContainer(); pico.addComponent(Carrot.class) .addComponent(Cheese.class) .addComponent(Mixer.class); // fails with org.picocontainer.PicoCompositionException: java.lang.NoSuchMethodException: ...$Mixer.<init>() final Utensil u = pico.getComponent(Utensil.class); assertEquals("Mixing carrot with some cheese", u.use()); } public static final class Cheese { } public static final class Carrot { } public static interface Utensil { String use(); } public static class Spoon implements Utensil { public String use() { return "there is no spoon"; } } public static class Mixer implements Utensil { private final Cheese cheese; @Inject private Carrot veg; public Mixer(Cheese cheese) { this.cheese = cheese; } public String use() { return "Mixing " + simpleClassNameOrNull(veg) + " with some " + simpleClassNameOrNull(cheese); } } private static String simpleClassNameOrNull(Object o) { return o == null ? null : o.getClass().getSimpleName().toLowerCase(); }
Fix in Pico 3 git repos.