我有带有StandardizedAddressRepository
属性的@Component
类
@Component
public class StandardizedAddressRepository implements Runnable {
public StandardizedAddressRepository(BufferedReader reader, SqsMessage sqsMessage) throws IOException {
}
}
题:
如何将参数传递给
StandardizedAddressRepository
?我可以传递没有@Component属性的参数,但是我不想删除它。
提前致谢
最佳答案
您需要添加一个Configurator
类,以便为BufferedReader
和SqsMessage
类注入依赖项。您的代码应如下所示:
@Configuration
public class Configurator {
@Bean
public BufferedReader bufferedReader() throws FileNotFoundException {
return new BufferedReader(new FileReader(""));
}
@Bean
public SqsMessage sqsMessage(){
return new SqsMessage();
}
}