典型使用场景
在单例 Bean 中获取原型 Bean 的新实例
@Component
@Scope("prototype")
public class MyPrototypeBean {
private final String id = UUID.randomUUID().toString();
public String getId() {
return id;
}
}
@Component
public abstract class MySingletonService {
// 每次调用 getMyPrototypeBean() 都会返回一个新的实例
@Lookup
public abstract MyPrototypeBean getMyPrototypeBean();
public void doSomething() {
System.out.println("Prototype ID: " + getMyPrototypeBean().getId());
}
}