龙目岛不适用于spring-boot-maven

时间:2018-09-20 13:28:09

标签: java spring spring-boot lombok

我有一个带有spring-boot的项目,我使用了spring 2.0.5.RELEASE版本。而且,当我简化getter和setter以及有无字段的controctor的工作时,我想使用Lombok,这是我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>

在“大纲”视图中,当我选择班级的窗口时,我看不到getter和setter方法,这是我的Etudiant课程的源代码:

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;

}

我在此代码中有什么错误,您会写什么并添加到我的代码中,因为我的班级正确吗?

3 个答案:

答案 0 :(得分:1)

如果您的问题是您看不到getter和setter没问题,因为lombok在Etudiant.class文件的编译时提供了它 但是您必须在IDE中使用lombok插件

设置指南https://projectlombok.org/setup/overview

答案 1 :(得分:0)

这应该可行,尝试一下;

  1. 该项目具有lombok依赖性。首先查看您的.m2 仓库,如果没有,找到龙目岛罐子!
  2. 双击在jar上,指定IDE的路径,例如C:\Users\ide\install\package\yourIDE.exe
  3. 重新启动IDE并更新Maven项目。

答案 2 :(得分:0)

LomBok在m2文件夹(mvn缓存文件夹)中有一个jar 例如:C:\ Users \ Mypc \ .m2 \ repository \ org \ projectlombok \ lombok \ 1.18.12(基于必须执行的mvn软件包)将搜索ide

enter image description here

然后您需要重新启动ide,然后在类中进行搜索,您会看到getter和setters