简体   繁体   中英

Lombok doesn't work with spring-boot-maven

I have i project with spring-boot i used spring 2.0.5.RELEASE version. And i want to use the Lombok when i simplify my work for the getter and setter and the controctor with and without fields this is the file of my 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>hr.access</groupId>
<artifactId>ms-EtudiantS-Formation</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>ms-EtudiantS-Formation</name>
<description>Demo project for Spring Boot</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.5.RELEASE</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF- 
     8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-rest</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </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>
        </plugin>
    </plugins>
</build>
</project>

And in the view of Outline I don't see the getters and setters when I select the window of my class This is the sourcecode of my Etudiant class:

package hr.access.entities;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

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

@Entity
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Etudiant {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(length = 80)
private String nom;
@Column(length = 80)
private String prenom;
@Temporal(TemporalType.DATE)
private Date dateNaissance;

}

What is my mistake in this code what do you write and add to my code because my class is correctly?

if your problem is that you don't see the getters and setters that's not a problem as lombok provide it in compile time in Etudiant.class file but you must use lombok plugin in your IDE

setup guide https://projectlombok.org/setup/overview

This should work, try it;

  1. The project has lombok dependency. First look into your .m2 repository and if not ,find the lombok jar!
  2. Double click on jar, specify the path for IDE like C:\\Users\\ide\\install\\package\\yourIDE.exe
  3. Restart the IDE and update the maven project.

LomBok has a jar inside m2 folder (mvn cache folder) eg: C:\\Users\\Mypc \\ .m2 \\repository\\org\\projectlombok\\lombok\\1.18.12 based on the mvn package that has to be executed it will search for ide

在此处输入图片说明

and then you need to restart your ide then if you search within the class you can see getter and setters

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM