MethodInvokingFactoryBean的用法

网友投稿 559 2022-11-09

MethodInvokingFactoryBean的用法

MethodInvokingFactoryBean的用法

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="data-id="p838747a-WVQOALU0">xmlns:xsi="data-id="p838747a-ECWnV6TV">xsi:schemaLocation="data-id="p838747a-B5kaCJ77"><bean id="teacher"class=

"org.springframework.beans.factory.config.MethodInvokingFactoryBean">

<property name="staticMethod">

<value>com.teacher.Teacher.setStudentDao</value>

</property>

<property name="arguments">

<list>

<ref bean="studentDao" />

</list>

</property>

</bean>

<bean id="studentDao" class="com.teacher.StudentDao">

</bean>

</beans>

package

public class

private static

public static String setStudentDao(StudentDao stuDao) {

        Teacher.studentDao = stuDao;

return "hello world";

    }

}

 

package com.teacher;

public class StudentDao {}

package com.teacher;

import org.springframework.test.

AbstractDependencyInjectionSpringContextTests;

public class Test

extends AbstractDependencyInjectionSpringContextTests{

 

@Override

    protected String[] getConfigLocations() {

        return new String[]{"applicationContext.xml"};

    }

    public void test(){

        Object o=getApplicationContext().getBeanFactory()

.getBean("teacher");

        System.out.println(o);

    }

}

 

MethodInvokingFactoryBean 调用指定的方法 并且得到返回值作为bean对象,如果是void方法,则返回null;

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:springBoot整合rabbitmq测试常用模型小结
下一篇:ExtJs 实现类似QQ的提示消息框
相关文章

 发表评论

暂时没有评论,来抢沙发吧~