我有一个 Spring Boot 项目,并且我已经配置了 Lombok。
我的pom.xml如下:
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.32</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
我有一个 DTO 类,用 Lombok 的
@AllArgsConstructor
注释,如下:
@Getter
@Setter
@AllArgsConstructor
public class CustomerDto {
String username;
String password;
}
但是,当我执行
maven clean compile
甚至 maven clean install
时,生成的代码 (/target/classes/com/example/...
) 是
public class CustomerDto {
String username;
String password;
public CustomerDto() {
}
}
似乎没有全参数构造函数,我不知道为什么。这是为什么?
我尝试跑步
mvn clean install
和mvn clean compile
。我尝试使用 Lombok 生成静态工厂方法而不是全参数构造函数,这似乎也没有出现在编译的类中。
您需要在 maven-compiler-plugin 中配置 lombok 注释处理器
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.12</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>