I have a Util class which have some static methods. I want to use spring beans, so i have added few service classes as beans in my util class. As far as i know its not a good practice to use spring beans as a static fields. But is there any way to access spring beans in a static method?
My example:
I had seen in many forms that this is not a best practice, can some one help me how can i handle this type of scenarios?Code:public class TestUtils { private static testBean; public void setTestBean(TestBean testBean) { TestUtils.testBean = testBean; } public static String getBeanDetails() { return beanName = testBean.getDetails(); } }
My xml has below value:
Code:<bean id="testUtils" class="com.test.TestUtils"> <property name="testBean" ref="testBean" /> </bean>


Reply With Quote
