复制代码

01 spring lookup-mothod 使用

1.背景

其实使用spring BeanDefinitionParseDelegate 进行bean解析时,会获取自己的look-up 标签进行解析 ,所以如何使用look-up 标签呢

2 代码块

User
 
package beans.lookUp;
/**
 * @author lianzheng
 * @date 2019-12-21 23:18
 * @service User
 */
public class User{
    public void showMe(){
        System.out.println("i am user");
    }
}
  
package beans.lookUp;

/**
 * @author lianzheng
 * @date 2019-12-21 23:18
 * @service Teacher
 */
public class Teacher extends User {
    public void showMe() {
        System.out.println("i am teacher");
    }
}
package beans.lookUp;

/**
 * @author lianzheng
 * @date 2019-12-21 23:19
 * @service GetBeanTest
 */
public abstract class GetBeanTest{
    public void showMe(){
        this.getBean().showMe();
    }

    public abstract User getBean();
}

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">


    <bean id="getBeanTest" class="beans.lookUp.GetBeanTest">
      <lookup-method name="getBean" bean="teacher"/> 
        <lookup-method name="getBean" bean="student"/>
    </bean>
    <bean id="teacher" class="beans.lookUp.Teacher"/>
    <!--  <bean id="student" class="beans.lookUp.Student"/> -->
</beans>
posted @ 2019-12-21 23:42  pg633  阅读(382)  评论(0编辑  收藏  举报