如何将 bean 读入其他 class

How to read bean into other class

我有这个配置class

@Configuration
@ComponentScan(value ="com.cloudgatewayservice")
@PropertySources({@PropertySource("classpath:application.yml"),
                 @PropertySource("file:${prm.target.account.config}")})
public class AccountInstanceConfig {

    @Autowired private Environment env;


    @Bean public List<String> accountInstance() {
        return Arrays.asList(env.getRequiredProperty("prm-account-instance").split("#"));
    }
}

我需要获取 accountInstance() return 值,但我不知道该怎么做。你能提供一些帮助吗?谢谢。

可以使用 @Autowired 注释吗?

现场:

@Autowired
private final List<String> accountInstance;

在构造函数中:

private final List<String> accountInstance;

@Autowired
public MyClass(List<String> accountInstance) {
    this.accountInstance = accountInstance;
}

或 setter:

private List<String> accountInstance;

@Autowired
public void setAccountInstance(List<String> accountInstance) {
   this.accountInstance = accountInstance;
}