가네시 :
사실 기존의 코드를 내가 자식에서 체크 아웃하고, 봄 부팅 2.X 응용 프로그램과 스프링 배치 작업입니다. 응용 프로그램을 실행하는 동안 만 저를 위해 아래의 오류로 인해 실패하고 동일한 코드가 다른 사람을 위해 노력하고 있습니다.
s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'inputItemReader' defined in file [C:\Users\XYZ\git\main\batch\CBatchProcessing\target\classes\com\main\batchprocessing\batch\reader\InputItemReader.class]: Unsatisfied dependency expressed through **constructor parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'java.lang.String' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations**: {}
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-10-16 23:23:37.411 ERROR 2384 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
**Parameter 0 of constructor in com.main.batchprocessing.batch.reader.InputItemReader required a bean of type 'java.lang.String' that could not be found.**
Action:
Consider defining a bean of type 'java.lang.String' in your configuration.
나는 아래에 체크 한
- 모든 봄의 구성 요소가 올바르게 등 저장소 @ 컨트롤러 @ @Component, @Service,,, 주석 있습니다 ...
- @ComponentScan 및 @EnableAutoCOnfiguration이 또한 제공된다.
- 선언에서 "java.lang.String의"를 제공했습니다.
암호:
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.StepExecutionListener;
import org.springframework.batch.item.file.FlatFileItemReader;
import org.springframework.batch.item.file.mapping.JsonLineMapper;
import
org.springframework.batch.item.file.separator.JsonRecordSeparatorPolicy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.core.io.FileSystemResource;
import org.springframework.stereotype.Component;
@Component
public class InputItemReader extends FlatFileItemReader<Map<String,
Object>> implements StepExecutionListener {
@Autowired
private InputFileHeaderValidator inputFileHeaderValidator;
@Autowired
private FileAuditService fileAuditService;
private final Logger log =
LoggerFactory.getLogger(InputItemReader.class);
private java.lang.String inputFilePath;
public InputItemReader(String inputFilePath) {
setLineMapper(new JsonLineMapper());
setRecordSeparatorPolicy(new JsonRecordSeparatorPolicy());
setResource(new FileSystemResource(inputFilePath));
this.inputFilePath = inputFilePath;
}
}
v_schoener :
공용 기본 생성자를 제공하지 않고 자신의 기본이 아닌 생성자를 추가하기 때문에 인스턴스가 실패합니다. 내가 좋아하는 속성으로 입력 파일 경로를 정의 할 수 건의 할 것입니다 @Value("${inputFilePath}")
. 당신이 당신의 빈에 추가 초기화를해야 할 경우 무효 방법을 정의하고 그것을 주석 @PostConstruct
과 내에서 초기화를.