我试图在一个项目中使用 lombok 它,在该项目中我有一个抽象基模型类,而其他类是从它派生出来的。但是我在编译时出错。代码如下所示:
基础实体.java
import java.util.Date;
import lombok.Data;
import org.springframework.data.annotation.Id;
@Data
public abstract class BaseEntity {
@Id
private String id;
private Date createdOn;
private Date modifiedOn;
private Status status;
}
用户.java
import lombok.Data;
@Data
public class User extends BaseEntity {
public static enum UserType {
GUEST, NORMAL, SELLER, ADMIN, SUPER_ADMIN
}
public static enum Gender {
MALE, FEMALE, NOT_SPECIFIED
}
private String firstName;
private String lastName;
private String emailId;
private String password;
private long phoneNumber;
private Gender gender;
private UserType userType;
private Address address;
}
编译时出现错误
[ERROR] Lombok annotation handler class lombok.javac.handlers.HandleData failed on D:\BolBuddy\bolbuddy\api\bolbuddy\src\main\java\in\bolbuddy\model\User.java: java.lang.NoSuchMethodError: com.sun.tools.javac.code.Type.<init>(ILcom/sun/tools/javac/code/Symbol$TypeSymbol;)V
java.lang.NoSuchMethodError: com.sun.tools.javac.code.Type.<init>(ILcom/sun/tools/javac/code/Symbol$TypeSymbol;)V
at lombok.javac.handlers.HandleSetter$JCNoType.<init>(HandleSetter.java:167)
at lombok.javac.handlers.HandleSetter.createSetter(HandleSetter.java:154)
at lombok.javac.handlers.HandleSetter.createSetterForField(HandleSetter.java:127)
at lombok.javac.handlers.HandleSetter.generateSetterForField(HandleSetter.java:89)
at lombok.javac.handlers.HandleData.handle(HandleData.java:111)
at lombok.javac.HandlerLibrary$AnnotationHandlerContainer.handle(HandlerLibrary.java:74)
at lombok.javac.HandlerLibrary.handleAnnotation(HandlerLibrary.java:168)
at lombok.javac.JavacTransformer$AnnotationVisitor.visitAnnotationOnType(JavacTransformer.java:71)
at lombok.javac.JavacNode.traverse(JavacNode.java:103)
at lombok.javac.JavacAST.traverseChildren(JavacAST.java:117)
at lombok.javac.JavacNode.traverse(JavacNode.java:66)
at lombok.javac.JavacAST.traverseChildren(JavacAST.java:117)
at lombok.javac.JavacNode.traverse(JavacNode.java:61)
at lombok.javac.JavacAST.traverse(JavacAST.java:112)
at lombok.javac.JavacTransformer.transform(JavacTransformer.java:52)
at lombok.javac.apt.Processor.process(Processor.java:105)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:794)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:705)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$1800(JavacProcessingEnvironment.java:91)
at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1035)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1176)
at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1170)
at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:856)
at com.sun.tools.javac.main.Main.compile(Main.java:523)
at com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:129)
at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:138)
at org.codehaus.plexus.compiler.javac.JavaxToolsCompiler.compileInProcess(JavaxToolsCompiler.java:126)
at org.codehaus.plexus.compiler.javac.JavacCompiler.performCompile(JavacCompiler.java:169)
at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:785)
at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:129)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:133)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:108)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:76)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:116)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:361)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:155)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:213)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:157)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
更新:
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>in.bolbuddy</groupId>
<artifactId>bolbuddy</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>bolbuddy</name>
<description></description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.5.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-social-facebook</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-social-linkedin</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-social-twitter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>0.9.2</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>projectlombok.org</id>
<url>http://projectlombok.org/mavenrepo</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
最佳答案
在您的 pom.xml
文件中,替换
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>0.9.2</version>
</dependency>
和
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>RELEASE</version>
<scope>provided</scope>
</dependency>
它对我有用。我在尝试
mvn clean install
时遇到了类似的问题。关于java - Lombok 注释处理程序类 lombok.javac.handlers.HandleData 失败,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32911820/