Spring 以动态和惰性的方式创建同一类的多个bean @ConfigurationProperties(“个人”) 公共类人员配置{ 私有列表详细信息=新建ArrayList(); //接球手、接球手和投球手 公共静态类详细信息{ 私钥; 私人弦公司; 私弦家庭; //接球手、接球手和投球手 } } 公共阶层人士{ 公共字符串密钥; 公共类obj; //建造师 //getter、setter和tostring } @组成部分 公营人员工厂{ @自动连线 人员配置人员配置; 公共人物getPerson(字符串键){ //如果PersonConfiguration中存在密钥 //基于相应密钥的族和组件详细信息创建SomeClass //使用key和SomeClass创建personbean。 } }
如何仅当基于请求中的不同键被请求时,才以惰性方式在上述类中创建多个Person beanSpring 以动态和惰性的方式创建同一类的多个bean @ConfigurationProperties(“个人”) 公共类人员配置{ 私有列表详细信息=新建ArrayList(); //接球手、接球手和投球手 公共静态类详细信息{ 私钥; 私人弦公司; 私弦家庭; //接球手、接球手和投球手 } } 公共阶层人士{ 公共字符串密钥; 公共类obj; //建造师 //getter、setter和tostring } @组成部分 公营人员工厂{ @自动连线 人员配置人员配置; 公共人物getPerson(字符串键){ //如果PersonConfiguration中存在密钥 //基于相应密钥的族和组件详细信息创建SomeClass //使用key和SomeClass创建personbean。 } },spring,spring-boot,Spring,Spring Boot,如何仅当基于请求中的不同键被请求时,才以惰性方式在上述类中创建多个Person bean 基本上有一个配置和工厂类。根据传入的请求,需要检查配置中是否存在该请求,如果存在,则需要使用factory类创建某种类型的对象。您能用示例更具体一些吗@用户希望在有人调用PersonFactory.getPerson并将其添加到applicationcontext时动态创建Person bean @ConfigurationProperties("person") public class PersonCo
基本上有一个配置和工厂类。根据传入的请求,需要检查配置中是否存在该请求,如果存在,则需要使用factory类创建某种类型的对象。您能用示例更具体一些吗@用户希望在有人调用PersonFactory.getPerson并将其添加到applicationcontext时动态创建Person bean
@ConfigurationProperties("person")
public class PersonConfiguration {
private List<Details> details = new ArrayList<>();
//getters and setters and tostring
public static class Details {
private String key;
private String company;
private String family;
//getters and setters and tostring
}
}
public class Person {
public String key;
public SomeClass obj;
//constructor
//getter, setter and tostring
}
@Component
public class PersonFactory {
@Autowired
PersonConfiguration personConfig;
public Person getPerson(String key) {
//if key exists in PersonConfiguration
//create SomeClass based on family and compnay details for corresponding key
//create Person bean using key and SomeClass.
}
}