[jboss-user] [JBoss Microcontainer] - How do I inject a static field when a constructor is private?
Zemian Deng
do-not-reply at jboss.com
Fri Apr 30 11:27:05 EDT 2010
Zemian Deng [http://community.jboss.org/people/saltnlight5] created the discussion
"How do I inject a static field when a constructor is private?"
To view the discussion, visit: http://community.jboss.org/message/540476#540476
--------------------------------------------------------------
Hi,
If have a simple POJO like this:
package mypkg;
import java.io.PrintStream;
class Foo {
private PrintStream printStream;
public void setPrintStream(PrintStream out) {
this.printStream = out;
}
public void run() {
printStream.println("test");
}
}
Now how would I inject the System.out into the bean in deployment? If do this, it gives me error on creating
JavaLangSystem bean, which make sense since it's constructor is private.
<bean name="JavaLangSystem" access-mode="FIELDS" />
<bean name="Foo" class="mypkg.Foo">
<property name="printStream"><inject bean="JavaLangSystem" property="out"/></property>
<start method="run" />
</bean>
So is there way I can quickly inject a static field in a class that has private constructor?
I do see some example that use a value-factory and a provider class like here http://anonsvn.jboss.org/repos/jbossas/projects/demos/microcontainer/trunk/ioc/src/main/resources/META-INF/access-mode-beans.xml http://anonsvn.jboss.org/repos/jbossas/projects/demos/microcontainer/trunk/ioc/src/main/resources/META-INF/access-mode-beans.xml, but it seems too involved to get a simple thing like this to be injected. Did I missed something?
Thanks,
Z
--------------------------------------------------------------
Reply to this message by going to Community
[http://community.jboss.org/message/540476#540476]
Start a new discussion in JBoss Microcontainer at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2114]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20100430/64d05ea3/attachment.html
More information about the jboss-user
mailing list