LoginSignup
2
2

More than 5 years have passed since last update.

IntelliJでlombokを使ったときはまった話

Posted at

概要

普段からIDEを使ってJavaで開発している人にとってはなんてことない話ですが
はじめて開発することになりはまったので備忘録+自分のような人が出ないようにのメモ(そんなのおらんか)

環境

  • spring boot 2.0.3
  • lombok 1.16.22
  • IntelliJ IDEA Community Edition 2018.1 x64

lombokとは

アノテーションをつけるだけでgetter,setterなどを自動で生成してくれる
Kotlinなんかは言語として組み込まれていた気がする。

導入

build.gradleに以下をいれるだけ

compile('org.projectlombok:lombok')

使用例

@Entity
@Data
@Table(name="counter")
public class Counter {

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private int id;

    @Column(name="title")
    private String title;

    @Column(name="count")
    private int count;
}

問題

spring bootのEntityを作成するときなどに便利だが
これだけだとアノテーションがきいていない(REST APIを作ってもEntityにうまくマッピングされていない)
コンパイルする時にはアノテーションを理解できるが展開はしてくれない模様。

[{},{},{},{},{}]

こんな返値になる。

原因

IDEにもpluginを入れないとダメ

Settings>Plugins>Browse Repository>"lombok"

で導入
再起動を求められるので行う
Settings>Build, Execution, Deployment>Compiler>Annotation ProcessorsでEnable annotation processingにチェック

ちゃんと返ってくるようになった

[{"id":1,"title":"all","count":0},{"id":2,"title":"select","count":0},{"id":3,"title":"update","count":0},{"id":4,"title":"delete","count":0},{"id":5,"title":"put","count":0}]

はじめてspring bootを使って開発をしていますがやたらとはまる。。。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2