Spring Lombok @AllArgsConstructor无法正常工作

时间:2019-06-22 14:28:26

标签: spring spring-boot spring-data spring-tool-suite

我正在使用lombok,但是当我创建该类的对象时,@ AllArgConstructor似乎无法正常工作,而Sts显示为

描述资源路径位置类型 构造函数Employee(String,String,String [])是未定义的EmployeeController.java / spring-solr / src / main / java / com / ajay / solr / controller第21行Java问题

package com.ajay.solr.model;

import org.apache.solr.client.solrj.beans.Field;
import org.springframework.data.annotation.Id;
import org.springframework.data.solr.core.mapping.SolrDocument;

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

@Data
@AllArgsConstructor
@NoArgsConstructor
@SolrDocument(collection = "Employee")
public class Employee {

    @Id
    @Field
    private int id;
    @Field
    private String name;
    @Field
    private String[] address;

}

我正在使用的班级是

package com.ajay.solr.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import com.ajay.solr.model.Employee;
import com.ajay.solr.repository.EmployeeRepository;

@RestController
    public class EmployeeController {
@Autowired
    private EmployeeRepository empRepository;

    public void addEmployees() {
        List<Employee> employees =  new ArrayList<>();
        employees.add(new Employee(373,"Sunil",new String[] {"Hyderabad","Gazipur"}));
        employees.add(new Employee(374,"Ajay",new String[] {"AnjaiyahNagar","Maharajganj"}));
        employees.add(new Employee(375,"Praveen",new String[] {"SRNagar","Baliya"}));
    }
}

1 个答案:

答案 0 :(得分:2)

如果您正在使用STS。您必须通过运行lombok-xyz.jar

在您的Eclipse中安装Lombok。

请尝试以下步骤:

1。在pom中包含pom。 2.退出/关闭STS 3.从https://projectlombok.org/download

中查找lombok Jar
4.From Command Prompt/Shell java -jar lombok-1.x.y.jar

这将打开一个弹出屏幕,然后为STS / Eclipse.exe指定路径

  1. 点击安装按钮

  2. 启动STS / Eclipse

(如果仍然遇到问题,请尝试更新项目:右键单击项目-> Maven->更新项目,错误将消失。)