Lombok

Intellij IDEA中Mybatis Mapper自动注入警告的6种解决方案

怎甘沉沦 提交于 2019-11-30 09:47:59
相信使用Mybaits的小伙伴们一定会经常编写类似如下的代码: 可以看到 userMapper 下有个红色警告。虽然代码本身并没有问题,能正常运行,但有个警告总归有点恶心。本文分析原因,并列出解决该警告的几种方案。 原因 众所周知,IDEA是非常智能的,它可以理解Spring的上下文。然而 UserMapper 这个接口是Mybatis的,IDEA理解不了。 而 @Autowired 注解,默认情况下要求依赖对象(也就是 userMapper )必须存在。而IDEA认为这个对象的实例/代理是个null,所以就 友好地给个提示 。 解决方案 方法1:为 @Autowired 注解设置required = false 使用 @Autowired 注解时,若希望允许null值,可设置required = false,像这样: @Autowired(required = false) private UserMapper userMapper; 这样就不会有警告了。原因很好理解:IDEA认为userMapper是个null,给了警告;加上required = false后,使用 @Autowired 注解不再去校验userMapper是否存在了。也就不会有警告了。 总结 :这种方式有点蛋疼。一个庞大的既有项目,可能到处都在引用Mapper,总不能到处都补上 required = false

How to set up compile library in android studio. LOMBOK

给你一囗甜甜゛ 提交于 2019-11-30 08:44:43
Help me to set up comile dependencies in Android Studio in build.gradle. I mean that they not include into final APK. this build.gradle works fine but i don't need lombok library in apk in runtime; apply plugin: 'android' android { compileSdkVersion 19 buildToolsVersion "19.0.0" defaultConfig { minSdkVersion 10 targetSdkVersion 16 versionCode 1 versionName "1.0" } buildTypes { release { runProguard false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' } } } dependencies { compile 'com.android.support:appcompat-v7:+' compile 'org.projectlombok:lombok:1.12.2' }

Spring Boot 2 实战:集成 MapStruct 类型转换神器

我与影子孤独终老i 提交于 2019-11-30 08:21:51
1. 痛点 一种框架的出现都要解决个痛点,我想下面这这种不方便的操作经常有人写吧。 假如 Car 类是数据库映射类: ​​ package cn.felord.mapstruct.entity; import lombok.Data; /** * Car * * @author Felordcn * @since 13:35 2019/10/12 **/ @Data public class Car { private String make; private int numberOfSeats; private CarType type; } CarType 类: package cn.felord.mapstruct.entity; import lombok.Data; /** * CarType * * @author Felordcn * @since 13:36 2019/10/12 **/ @Data public class CarType { private String type; } ​​ CarDTO 是DTO类: package cn.felord.mapstruct.entity; import lombok.Data; /** * CarDTO * * @author Felordcn * @since 13:37 2019/10/12 **/

Lombok @Builder inheritance workaround

无人久伴 提交于 2019-11-30 07:06:38
问题 Lombok @Builder doesn't work for inheritance use cases: For example class Foo{ protected int xyz1; ..... protected String xyz7; } class Bar extends Foo{ } For given use case Lombok will not be able to generate methods to set value of parameter defined in Foo class. A workaround for this is: Manual creating constructor of Bar. Putting a Builder annotation on that constructor. Is there a better workaround ? 回答1: Lombok has introduced experimental features with version: 1.18.2 for inheritance

Lombok and Maven

浪尽此生 提交于 2019-11-30 05:01:50
I'm trying to use Lombok with Maven and VRaptor on IntelliJ but it doesn't work. I already read some info in stackoverflow but none solved my problem, i already enabled the Annotation Processor in Intellij but still nothing. I tryied to compile it from command-line too (Windows) and didn't work. I also tryed to create another project without maven and add the library, create some classes for test and it works, compile and run perfectly. Any help? The project has only 2 class, 1 entity and 1 controller Here is my pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www

安装lombok 与阿里巴巴扫描规范 与取消扫描

喜欢而已 提交于 2019-11-30 03:44:40
一、安装lombok 1、先下载lombok的jar 放到eclipse的安装路径 2、打开 eclipse.ini文件 添加引入lombok的jar 我这里是这样的: -javaagent:D:\Program Files\eclipse\eclipse\lombok.jar 3、使用 引入pom文件 <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.16.10</version> </dependency> 代码: 效果: 二、安装阿里巴巴代码扫描规范 第一步:安装插件 Help >> Install New Software 然后在框中输入URL: https://p3c.alibaba.com/plugin/eclipse/update 安装完成后,重启Eclipse! 使用: 点击文件右键扫描即可, 取消:close project 再 open 就OK了。 做技术最难能可贵的就是持续的学习,吸收知识,不断的思考形成自己的理解和模式。 欢迎进QQ群讨论:600922504 来源: https://my.oschina.net/960823/blog/3108322

Maven Scope for Lombok (Compile vs. Provided)

青春壹個敷衍的年華 提交于 2019-11-30 03:07:47
I recently found out that the lombok.jar ends up in our final artifact, which shouldn't be necessary. In my understanding lombok is compile-time only. <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.14.4</version> </dependency> But when I set it to scope provided, I get strange behaviour in unit tests. They crash with ClassNotFoundExceptions then when trying to resolve java.lang.NoClassDefFoundError: com/svv/esp/serviceimpl/dataimport/common/validation/LongValidator Which maven scope is in general used for lombok? I'm using Oracle JDK build 1.8.0_25

ObjectMapper can't deserialize without default constructor after upgrade to Spring Boot 2

邮差的信 提交于 2019-11-30 01:34:46
I have following DTOs: @Value public class PracticeResults { @NotNull Map<Long, Boolean> wordAnswers; } @Value public class ProfileMetaDto { @NotEmpty String name; @Email String email; @Size(min = 5) String password; } @Value is a Lombok annotation which generates a constructor. Which means that this class doesn't have a no-arg constructor. I used Spring Boot 1.4.3.RELEASE and ObjectMapper bean was able to deserialize such object from json. After the upgrade to Spring Boot 2.0.0.M7 I receive following exception: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct

What does the syntax `@__()` mean in Lombok?

血红的双手。 提交于 2019-11-30 01:11:57
问题 I have been working with and actively using Lombok for 2 months. With Java I'm a little more familiar. But, for the first time, I was faced with the following syntax structure in the language: @RequiredArgsController(onController = @__(@Autowired)) ^^^ What does that mean, and how does it get compiled? 回答1: This is an experimental Lombok syntax, created to support a layer of indirection when referencing multiple annotations, rather than use a Class<?>[] . The syntax is a little strange; to

Unable to use Lombok with Java 11

狂风中的少年 提交于 2019-11-30 00:17:46
问题 We upgraded the Java version from 8 to 11 but I got compile errors of getter/setter methods where I implemented the POJO classes with Lombok's Getter and Setter Annotations. Is there a way to use Lombok's @Data annotation which provides getter and setter without implementing them at Java 11? Currently, I am facing the error: unable to find getStoreName() where storeName was declared as a global variable in the class with @Data Lombok annotation above the class. 回答1: TL;DR Upgrade Lombok as a