简体   繁体   中英

Bean definition for using a class with static methods in Spring Controller class

I have a TestUtil class that I need to use in almost each of my other classes in a Spring MVC web application.

In my application context, I have done the following bean definitions:

<bean id="masterbo" class="com.bo.master.MasterBO">
    <property name="masterdao" ref="masterdao"></property>
    <property name="testutil" ref="testutil"></property>
</bean>

<bean id="masterdao" parent="daoSupport" class="com.dao.master.MasterDAO"></bean>
<bean id="testutil" class="com.util.TestUtil"></bean>

I have autowired the TestUtil class in MasterBO and simply used the testutil.someMethod() call.

Using this I am able to use the static method from TestUtil in MasterBO. Now, I would like to do the same in the MasterController. Similar bean definition is not working in that case

Can anyone guide me regarding the bean definition that needs to be done?

EDIT: Calling static methods directly is working on Tomcat. Facing this issue on WildFly and JBoss, which supposedly require proper bean definition.

SOLVED: It seems there was an incorrect ParseException being used in the Util which was conflicting with WildFly

您不需要实例化bean来调用静态方法,只需直接由类本身调用该方法: TestUtil.someMethod()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM