Parameter 0 of constructor in required a bean of type 'java.lang.String' that could not be found

前端 未结 10 2471
深忆病人
深忆病人 2021-02-07 01:41

I am working on spring batch with spring boot 2.X application, actually its existing code i am checked out from git. While running the application it fails due to below error on

相关标签:
10条回答
  • 2021-02-07 01:59

    Since you do not provide the public default constructor and you added your own non-default constructor the instantiation will fail. I would suggest you to define the input file path as property like @Value("${inputFilePath}"). If you need further initialization in your bean define a void method and annotate it with @PostConstruct and do the initialization within.

    0 讨论(0)
  • 2021-02-07 01:59

    I was facing the same issue and it got fixed by removing Constructors from my Model class. Adding sample snippet below:

    Map<String, ServiceDefinition> serviceDefinitionMapper = new HashMap<>();
        A def;
        B serviceCharacter;
    
        @Autowired
        public Scan(Map<String, ServiceDefinition> serviceDefinitionMapper, A def,
                B serviceCharacter) {
            super();
            this.serviceDefinitionMapper = serviceDefinitionMapper;
            this.def = def;
            this.serviceCharacter = serviceCharacter;
        }
    

    Please Note: Do not keep any Constructor/@AllArgsConstructor in your Model class unless it is very much needed to be decalred.

    0 讨论(0)
  • 2021-02-07 02:02

    The issue in my case was a redundant @Autowired, I initially added a dependency using @Autowired, by eventually commented it out, however I forgot to comment the annotation, due to which the method next to @Autowired was considered as some sort of setter.

    On removing the redundant annotation it is working fine.

    0 讨论(0)
  • 2021-02-07 02:02

    I had the same error but the error was generated by Feign Client. If you have this error using feign client you must add @EnableFeignClients on your main class:

    @SpringCloudApplication
    @EnableFeignClients
    public class Application {
    ...
    }
    
    0 讨论(0)
  • 2021-02-07 02:07

    I also had the same error:

    ***************************
    APPLICATION FAILED TO START
    ***************************
    
    Description:
    
    Field repository in com.example.controller.CampaignController required a bean of type 'com.example.data.CustomerRepository' that could not be found.
    
    
    Action:
    
    Consider defining a bean of type 'com.example.data.CustomerRepository' in your configuration.de here
    

    I solved this issue by adding @EnableMongoRepositories annotation in the main class:

    @SpringBootApplication
    @EnableMongoRepositories(basePackageClasses = CustomerRepository.class)
    public class CampaignAPI {
    
        public static void main(String[] args) {
            SpringApplication.run(CampaignAPI.class, args);
        }
    }
    
    0 讨论(0)
  • 2021-02-07 02:09

    in my case, the issue was way different.

    @SpringBootApplication
    @EnableNeo4jRepositories("com.digital.api.repositories") // <-- This was non-existent.
    public class Application {
    
        public static void main(String[] args) {
            SpringApplication.run(Application.class, args);
        }
    }
    

    Look at the @EnableNeo4jRepositories annotation. The package defined, was non-existent. Try defining that package, and be careful that the Repository interfaces are based there. Otherwise, Spring will not find the repositories classes that it should load up!

    0 讨论(0)
提交回复
热议问题