- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有下面的 Pojo 类,我添加了来自 Lombok
的 @Data
。
该项目在 Eclipse IDE 中运行良好,我什至可以在 IDE 的大纲窗口中看到 getter/setter。但是,当我从 IDE 运行 mvn clean install
或 Run As Maven Install
时,生成的 jar 文件没有任何错误,但没有方法(getters
、setters
、equals
、hashcode
)由Lombok
生成。
既然IDE正在显示方法,那么POM文件中的maven编译器插件肯定存在一些问题。我尝试了 SO 中的所有可能的解决方案,但没有任何效果。
这是 POM:
<?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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>example</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>test-boot</name>
<description>Demo project</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</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>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>1.3.0.Final</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerArgument>-proc:none</compilerArgument>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</path>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.3.0.Final</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</project>
我已将测试项目推送到Github 。可以从这里克隆:https://github.com/Puspendert/test-lambok.git
更新:为了验证 getter/setter 的生成是否会产生任何影响,我更改了 main 方法:
@SpringBootApplication
public class TestBootApplication {
public static void main(String[] args) {
User user = new User();
user.setName("hero");
System.out.println(user.getName());
}
}
然后,正如预期的那样,该项目在 mvn clean install
上出现编译错误:
[INFO] Building test-boot 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ example ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ example ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 3 source files to /Users/puspender/git/test-lambok/test-boot/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /Users/puspender/git/test-lambok/test-boot/src/main/java/com/example/TestBootApplication.java:[11,21] cannot find symbol
symbol: method setName(java.lang.String)
location: variable user of type com.example.User
[ERROR] /Users/puspender/git/test-lambok/test-boot/src/main/java/com/example/TestBootApplication.java:[12,40] cannot find symbol
symbol: method getName()
location: variable user of type com.example.User
[INFO] 2 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
请提出建议,这里可能出了什么问题?
最佳答案
您正在明确禁用注释处理!
<compilerArgument>-proc:none</compilerArgument>
删除这一行 - lombok 毕竟是一个注释处理库 - 并且所有内容(应该)工作文件
编辑:为了公平起见,还有另一个被删除的答案(出于某种原因),这也表明
关于java - Maven 编译器未将 getters/setters(使用 Lombok 生成)添加到构建 jar 文件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55247371/
如果您有一个具有一些普通 get/set 属性的类,是否有任何理由在类方法中使用 getter,或者您应该只使用私有(private)成员变量?我认为关于setter(验证逻辑?)可能会有更多争论,但
我是 Android 编程的新手(~ 2 个月)有必要为几十个不同的变量设置 getter 吗? 例如—— //Yes I realise that this isn't 'dozens' publi
我是VUEX新手,在学习VUEX的同时搭建了一个测试应用。我已将我的 VUEX 存储拆分为多个模块,每个模块都有自己的 getter.js 文件。 Getters、 Action 、突变被导入到每个模
我有一项服务正在加载我想在多个组件之间共享的基本系统信息。 如果我在 getter 中创建一个 getter 方法 this 如果我不在服务中使用双箭头,则 getter 中的 this 成为组件的
tl;博士 如何从参数化的 getter 访问其他 getter? 通常可以使用this.myGetter ;但是参数化的 getter 被实现为箭头函数,其中 this未定义。 在 Pinia 中处
我第一次尝试做一些 OOP,这不是简单的练习,而是用 java 编写一个程序来存储有关人员的信息(如通讯录)。下面是我正在开发的名为 Person 的类的片段。 Person 将在将来的某个时间被其他
我在某处看到类似下面的内容,想知道它是什么意思。我知道他们是getter和setter,但是想知道为什么字符串Type是这样定义的。谢谢你帮助我。 public string Type { get;
Public class Example { private int number; public Example(int number){ this.number =
getter 应该只返回对象吗: public MyObject getMyObject() { return myObject; } 或者它应该复制它返回的对象并返回该副本? public
我目前正在处理大量数据输入,包括很多值,我希望在 getter 中接收这些值以供以后使用。 在编写了一些方法之后,我想知道仅使用一个 get 方法是否是一个更好的主意,并使用一个包含所有可能值的枚举类
我正在使用新的 Class Public Field Declarations可用 Chrome 72我遇到了这种真正奇怪的行为: class Extended { property = 5; }
我有一个这样的表达式 setter/getter : var expression = () => SomeInstance.Nr; 它被传递到一个方法中: public void AddExpres
我的一个类(class)中有以下 getter: get password(){ if(this._public) return null; var text = ""
我已经设法测试了与其他代码隔离的 Vuex getter。当 getter 依赖于其他 getter 时,我现在面临一些问题,请参见以下示例: getters.js export const gett
有时我的任务是查找 getter 返回的值中的某些嵌套 getter 是否具有某些属性。经典的 C++ 会是这样的: for (const auto& label: labels) for (co
我有一个像这样的基类“Parent”: using System; using System.Collections.Generic; using System.Text; namespace Con
我一直在努力了解 getter 和 setter,但没有深入了解。我读过 JavaScript Getters and Setters和 Defining Getters and Setters只是没
考虑一个简单的 Vue 博客: 我使用 Vuex 作为我的数据存储,我需要设置两个 getters :一个 getPost getter,用于通过 ID 检索 post,以及一个 listFeatur
我有一个 VueX 商店,有两个模块,user.js 和merchant.js,顶层是index.js。 user.js 中的 getter 是: 重构 const getters = { s
我正在尝试向 jsp 添加一个复选框以在进入站点之前接受条款和条件。尽管我有一个 getter 方法并且没有看到任何拼写错误,但我一直收到关于没有 getter 方法的相同错误。我不明白我错过了什么。
我是一名优秀的程序员,十分优秀!