spring注入的方式实现静态方法中使用非静态变量

来源:互联网 发布:工业设计主流软件 编辑:程序博客网 时间:2024/06/05 23:29

实现静态方法中使用非静态变量

代码示例:

public class TestClass{  private SystemConfig config;  private static TestClass test;  public TestClass(){      test = this;      test.config = this.config;  }  public static void methodNam(){     Object obj = test.config.getMethodName();  }     public SystemConfig getConfig(){    return config;  }  pulbic void setConfig(SystemConfig config){   this.config = config; }}<span style="font-family: Arial, Helvetica, sans-serif;"></span>


bean配置

<bean name = "config" class="com.xuchao.ods.SystemConfig" />

<bean class="com.xuchao.ods.TestClass">

  <property name="config" ref = "config" />

</bean>




0 0
原创粉丝点击