具有运行时构造函数参数的 Spring Bean
2022-09-01 02:26:23
						我想在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);
    }
}
但是我得到了一个错误,源系统无法连接,因为没有找到豆子。如何使用运行时构造函数参数创建 Bean?
我正在使用春季 4.2
 
					 
				 
				    		 
				    		 
				    		 
				    		