package com.example.springboottest.config;
import com.example.springboottest.bean.MyBean;
import org.springframework.beans.factory.annotation.Lookup;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
import javax.annotation.PostConstruct;
@Configuration
public abstract class Config {
@Bean
@Scope("prototype")
//@Scope("singleton")
public MyBean myBean() {
return new MyBean();
}
@Lookup
public abstract MyBean proMyBean();
@PostConstruct
public void test() {
System.out.println(proMyBean());
System.out.println(proMyBean());
System.out.println(proMyBean());
}
}
输出:
com.example.springboottest.bean.MyBean@21d5c1a0
com.example.springboottest.bean.MyBean@4de025bf
com.example.springboottest.bean.MyBean@538613b3
针对 lookup方法和replace方法
源码中会进行如下处理:
验证及准备覆盖的方法
prepare method overrides -----》loockup method和replace method
最终使用cglib 重写lookup方法