Vincent van Beveren
2010-02-11 11:33:14 UTC
Hi everyone,
I'm new to pico-container, so bare with me :).
I'm trying to instantiate a PostgresSQL datasource, with PicoContainer 2.9. The datasource itself has methods like setUser, setServerName, etc... Also I wish this to be configurable. I've created the following code:
MutablePicoContainer pico = new DefaultPicoContainer();
pico.addConfig("serverName", "localhost");
pico.addConfig("databaseName", "mydb");
pico.addConfig("user", "user");
pico.change(Characteristics.USE_NAMES, Characteristics.SDI);
pico.addComponent(PGConnectionPoolDataSource.class);
PGConnectionPoolDataSource ds = pico.getComponent(PGConnectionPoolDataSource.class);
System.out.println(ds.getUser());
Exception in thread "main" org.picocontainer.injectors.AbstractInjector$AmbiguousComponentResolutionException: <no-component> needs a 'java.lang.String' injected, but there are too many choices to inject. These:[class java.lang.String, class java.lang.String, class java.lang.String], refer http://picocontainer.org/ambiguous-injectable-help.html
At the getComponent() call.
I tried to tell it that it needs to use the named version, but it doesn't seem to do it. What am I doing wrong? The next step would be to use properties loaded from a Properties file... I guess that should not be a problem once I get the above example working. Anyway, thanks for any help/examples!
Regards,
Vincent
___
Ing. V. van Beveren
Software Engineer, FOM Rijnhuizen
T: +31 (0) 30-6096769
E: V.vanBeveren-***@public.gmane.org<mailto:V.vanBeveren-***@public.gmane.org>
I'm new to pico-container, so bare with me :).
I'm trying to instantiate a PostgresSQL datasource, with PicoContainer 2.9. The datasource itself has methods like setUser, setServerName, etc... Also I wish this to be configurable. I've created the following code:
MutablePicoContainer pico = new DefaultPicoContainer();
pico.addConfig("serverName", "localhost");
pico.addConfig("databaseName", "mydb");
pico.addConfig("user", "user");
pico.change(Characteristics.USE_NAMES, Characteristics.SDI);
pico.addComponent(PGConnectionPoolDataSource.class);
PGConnectionPoolDataSource ds = pico.getComponent(PGConnectionPoolDataSource.class);
System.out.println(ds.getUser());
Exception in thread "main" org.picocontainer.injectors.AbstractInjector$AmbiguousComponentResolutionException: <no-component> needs a 'java.lang.String' injected, but there are too many choices to inject. These:[class java.lang.String, class java.lang.String, class java.lang.String], refer http://picocontainer.org/ambiguous-injectable-help.html
At the getComponent() call.
I tried to tell it that it needs to use the named version, but it doesn't seem to do it. What am I doing wrong? The next step would be to use properties loaded from a Properties file... I guess that should not be a problem once I get the above example working. Anyway, thanks for any help/examples!
Regards,
Vincent
___
Ing. V. van Beveren
Software Engineer, FOM Rijnhuizen
T: +31 (0) 30-6096769
E: V.vanBeveren-***@public.gmane.org<mailto:V.vanBeveren-***@public.gmane.org>