[JAVA] NoSuchMethodException with lombok without default constructor

A record of ordinary mistakes.

When I ran the following code using lombok, I got a run-time error.

@Data
@AllArgsConstructor
public class Person {
  ...
Caused by: java.lang.InstantiationException: kagamihoge.springbatchsample.Person
	at java.base/java.lang.Class.newInstance(Class.java:571) ~[na:na]
	at org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper.getBean(BeanWrapperFieldSetMapper.java:248) ~[spring-batch-infrastructure-4.2.1.RELEASE.jar:4.2.1.RELEASE]
	... 53 common frames omitted
Caused by: java.lang.NoSuchMethodException: kagamihoge.springbatchsample.Person.<init>()
	at java.base/java.lang.Class.getConstructor0(Class.java:3350) ~[na:na]
	at java.base/java.lang.Class.newInstance(Class.java:556) ~[na:na]
	... 54 common frames omitted

The cause was that the instantiation by reflection failed because there was no default constructor with no arguments.

So I specified lombok to also generate a no-argument constructor.

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Person {
  ..

Recommended Posts

NoSuchMethodException with lombok without default constructor
Specify the default value with @Builder of Lombok
Lombok with VS Code
[Java] How to omit spring constructor injection with Lombok
Lombok not working with Gradle5
Mock the constructor with PowerMock
Reduce verbose code with Lombok