Lombok 构造函数注释在 Java 23 中不起作用

问题描述 投票:0回答:1

Lombok 注释在带有 Java 23 的 NetBeans 23 中不起作用。我使用的是 Spring Boot。

我收到此错误:

com/veryona/jogos/controller/JogoController.java:[27,22] constructor Console in class com.veryona.jogos.model.Console cannot be applied to given types;
  required: no arguments
  found:    java.lang.String,java.lang.String,java.lang.String
  reason: actual and formal argument lists differ in length

这就是 JogoController 类中的内容:

List<Jogo> jogos = new ArrayList();
List<Console> consoles = new ArrayList();

@GetMapping("/menu")
public String mostrarMenu(Model model) {
    
    consoles.add(new Console("PS3", "Sony", "PlayStation 3"));
    consoles.add(new Console(
            "X360",
            "MicroSoft",
            "Xbox 360"
    ));
    consoles.add(new Console(
            "NWii",
            "Nintendo",
            "Wii"
    ));
    
    model.addAttribute("consoles", consoles);
    model.addAttribute("jogos", jogos);
    return "index";
}

控制台类:

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Console {
    
    String ID;
    String empresa;
    String nome;
}

我尝试在没有注释的情况下进行操作

@NoArgsConstructor
,但我收到了相同的错误

我的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 https://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>3.3.4</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.veryona</groupId>
    <artifactId>jogos</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>jogos</name>
    <description>databank de jogos</description>
    <url/>
    <licenses>
        <license/>
    </licenses>
    <developers>
        <developer/>
    </developers>
    <scm>
        <connection/>
        <developerConnection/>
        <tag/>
        <url/>
    </scm>
    <properties>
        <java.version>23</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

我只想使用 Lombok 制作的构造函数将数据插入到我的列表中。

java netbeans lombok
1个回答
0
投票

将 Lombok 插件添加到 IDE。它对我有用。

© www.soinside.com 2019 - 2024. All rights reserved.