我有带有StandardizedAddressRepository属性的@Component

@Component
public class StandardizedAddressRepository implements Runnable {

public StandardizedAddressRepository(BufferedReader reader, SqsMessage sqsMessage) throws IOException {
}
}


题:
如何将参数传递给StandardizedAddressRepository
我可以传递没有@Component属性的参数,但是我不想删除它。

提前致谢

最佳答案

您需要添加一个Configurator类,以便为BufferedReaderSqsMessage类注入依赖项。您的代码应如下所示:

@Configuration
public class Configurator {

    @Bean
    public BufferedReader bufferedReader() throws FileNotFoundException {
        return new BufferedReader(new FileReader(""));
    }

    @Bean
    public SqsMessage sqsMessage(){
        return new SqsMessage();
    }

}

08-16 18:48