How do I inject a static field when a constructor is private?

created by Zemian Deng in JBoss Microcontainer - View the full discussion



If have a simple POJO like this:


package mypkg;
class Foo {
     private PrintStream printStream;
     public void setPrintStream(PrintStream out) {
          this.printStream = out;
     public void run() {


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" />


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, but it seems too involved to get a simple thing like this to be  injected. Did I missed something?




Reply to this message by going to Community

Start a new discussion in JBoss Microcontainer at Community