我想在Spring Java配置中创建一个Spring bean,并在运行时传递一些构造函数参数.我创建了以下Java配置,其中有一个bean fixedLengthReport,它需要构造函数中的一些参数.
@Configuration
public class AppConfig {
@Autowrire
Dao dao;
@Bean
@Scope(value = "prototype")
**//SourceSystem can change at runtime**
public FixedLengthReport fixedLengthReport(String sourceSystem) {
return new TdctFixedLengthReport(sourceSystem, dao);
}
}
Run Code Online (Sandbox Code Playgroud)
但我收到的错误是sourceSystem无法连接,因为没有找到bean.如何使用运行时构造函数参数创建bean?
我使用的是Spring 4.2