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
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.
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.
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.
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 {
...
}
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);
}
}
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!