4
votes

I've created project with spring.

dependencies {
    compile('org.springframework.boot:spring-boot-starter-cache')
    compile('org.springframework.boot:spring-boot-starter-data-jpa')
    compile('org.springframework.boot:spring-boot-starter-data-rest')
    compile('org.springframework.boot:spring-boot-devtools')
    compile('org.projectlombok:lombok')
    compile('org.springframework.boot:spring-boot-starter-thymeleaf')
    compile('org.springframework.boot:spring-boot-starter-web')
    compile('org.codehaus.groovy:groovy')
    runtime('com.h2database:h2')
    runtime('mysql:mysql-connector-java')
    testCompile('org.springframework.boot:spring-boot-starter-test') 
    testCompile('org.springframework.restdocs:spring-restdocs-mockmvc')
}

application.properties:

spring.data.rest.base-path=/api

spring.datasource.url=jdbc:mysql://localhost/secret_backend
spring.datasource.username=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update

And the entity class:

package com.app.Entity

import lombok.Data

import javax.persistence.Entity
import javax.persistence.GeneratedValue
import javax.persistence.Id
import javax.persistence.Table

@Data
@Entity
@Table(name = "cities")
public class City {

    private @Id @GeneratedValue Long id;
    private String slug;
    private String title;
    private String titleShort;

    private City() {}

    /*public String getSlug(){
        return slug;
    }*/

    public City(String slug) {
        this.slug = slug;
    }
}

When I'm navigating to localhost:8080/api/cities, I don't see actual data form database:

{
  "_embedded": {
    "cities": [
      {
        "_links": {
          "self": {
            "href": "http://localhost:8080/api/cities/7"
          },
          "city": {
            "href": "http://localhost:8080/api/cities/7"
          }
        }
      },
      {
        "_links": {
          "self": {
            "href": "http://localhost:8080/api/cities/8"
          },
          "city": {
            "href": "http://localhost:8080/api/cities/8"
          }
        }
      },
...

Only if I'm adding getters to entity I see the data, but from lombok documentation @Data annotation must generate getters and setters for all entity properties.

1
Did you check the actual output? Did lombok instrument the classes? Also, lombok is only needed for compilation time not runtime. - highstakes
Actual output? Maybe some info for java(spring) dummy? And lombok is in compile('org.projectlombok:lombok') - Cawa
I mean, check the compiled .class files and see if the methods have been added into them (use a java decompiler or the 'javap' command on it). Compile dependency means it will be included in the produced artifact, this would be provided scope (which you need a plugin for in gradle) though this is unimportant. - highstakes
I've checked compiled entity, and theres no getters and setters pastie.org/10759960 So it seems that lombock is not working - Cawa
You should try running lombok in isolation on your class. It is an annotation preprocessor which could interfere with other preprocessors if done incorrectly. - highstakes

1 Answers

1
votes

Renamed City.groovy to City.java, and now it working fine. Thanks to @highstakes