title: Accessing spring beans in static method
body: <p>I have a Util class with static methods. Inside my Util class, I want to use spring beans so I included them in my util class.
  As far as I know it's not a good practice to use spring beans as static fields.
  But is there any way to access spring beans in a static method?</p>
  
  <p>My example:</p>
  
  <pre><code>public class TestUtils {
  
     private static TestBean testBean;
  
     public void setTestBean(TestBean testBean) {
       TestUtils.testBean = testBean;
     }
  
    public static String getBeanDetails() {
      return beanName = testBean.getDetails();
    }
  }
  </code></pre>
  
  <p>I have seen in many forums that this is not a best practice. Can someone show me how I can handle this type of scenario?</p>
  
  <p>My configuration file:</p>
  
  <pre><code>&lt;bean id="testUtils" class="com.test.TestUtils"&gt;
   &lt;property name="testBean" ref="testBean" /&gt;
  &lt;/bean&gt;
  </code></pre>