Parámetro 0 de constructor en un grano requerido del tipo 'java.lang.String' que no se pudo encontrar

ganesh:

Estoy trabajando en lotes de primavera con la aplicación 2.X arranque de primavera, en realidad su código existente YO SOY desprotegido de git. Mientras se ejecuta la aplicación que falla debido a continuación error sólo para mí y mismo código está trabajando para otros.

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.

He comprobado a continuación

  1. Todos los componentes de la primavera se anotan correctamente con @Component, @Service, Controlador @, @ repositorio, etc ...
  2. También se proporciona @ComponentScan y @EnableAutoCOnfiguration.
  3. Intentado dar "java.lang.String" en las declaraciones.

Código:

    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:

Dado que usted no proporciona el constructor por defecto pública y ha añadido su propio constructor no predeterminado la creación de instancias fallará. Yo sugeriría usted para definir la ruta del archivo de entrada como propiedad como @Value("${inputFilePath}"). Si necesita más de inicialización en el bean definir un método vacío y anotar con @PostConstructy hacer la inicialización dentro.

Supongo que te gusta

Origin http://43.154.161.224:23101/article/api/json?id=172196&siteId=1
Recomendado
Clasificación