Lombok

lombok and guice injection

荒凉一梦 提交于 2020-01-02 09:52:48
问题 I'm new to lombok and guice injection, I could get the general concept but I ran into some code which I don't understand and can't search due to the syntax. Following is the code, can someone help me understand this? import com.google.inject.Inject; import lombok.AccessLevel; import lombok.AllArgsConstructor; @AllArgsConstructor(access = AccessLevel.PRIVATE, onConstructor = @__({ @Inject })) public class SomeClass { ... } Thanks! 回答1: This is going to add a constructor with all fields as

lombok and guice injection

醉酒当歌 提交于 2020-01-02 09:52:18
问题 I'm new to lombok and guice injection, I could get the general concept but I ran into some code which I don't understand and can't search due to the syntax. Following is the code, can someone help me understand this? import com.google.inject.Inject; import lombok.AccessLevel; import lombok.AllArgsConstructor; @AllArgsConstructor(access = AccessLevel.PRIVATE, onConstructor = @__({ @Inject })) public class SomeClass { ... } Thanks! 回答1: This is going to add a constructor with all fields as

How to run code after constructor in a Lombok builder

核能气质少年 提交于 2020-01-01 02:30:09
问题 I have a class that I want to use Lombok.Builder and I need pre-process of some parameters. Something like this: @Builder public class Foo { public String val1; public int val2; public List<String> listValues; public void init(){ // do some checks with the values. } } normally I would just call init() on a NoArg constructor, but with the generated builder I'm unable to do so. Is there a way for this init be called by the generated builder? For example build() would generate a code like:

How to make Lombok + Gson work with Spring AOP proxies

浪尽此生 提交于 2019-12-31 04:03:47
问题 Assuming there is a simple class Student @Data @NoArgsConstructor @AllArgsConstructor public class Student { private Integer age; private String name; } Add a logging aspect With Spring AOP in aop.xml <aop:config> <aop:aspect id="log" ref="logging"> <aop:pointcut id="selectAll" expression="execution(* com.tutorial.Student.getName(..))"/> <aop:before pointcut-ref="selectAll" method="beforeAdvice"/> <aop:after pointcut-ref="selectAll" method="afterAdvice"/> </aop:aspect> </aop:config> <bean id=

【Spring Boot AOP记录用户操作日志】1. 集成mybatis基础框架

会有一股神秘感。 提交于 2019-12-30 12:28:46
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 在Spring框架中,使用AOP配合自定义注解可以方便的实现用户操作的监控。首先搭建一个基本的Spring Boot Web环境开启Spring Boot,然后引入必要依赖: <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <dependency> <groupId>org

How to override Lombok Setter methods

狂风中的少年 提交于 2019-12-30 08:18:08
问题 I'm using lombok in my project and generation Setters and Getters using @Setters and @Getters annotations on top of POJO class. I'm trying to override setters method of a property but it's not working I want to check if JSON property is Empty or Null i want to set default value in Setter method @Setter @Getter @NoArgsConstructor @AllArgsConstructor @Accessors(chain = true) @ToString public class DefaultModel { private String name; @Setter(AccessLevel.NONE)private String age; public void

Does Project Lombok support Java 9?

只谈情不闲聊 提交于 2019-12-29 04:08:38
问题 I have used Lombok in my project, but my colleague do not agree to use it, and his reason is (from controversy of lombok documents) Both of these pieces of Project Lombok make use of non-public APIs to accomplish their sorcery. This means that there is a risk that Project Lombok will be broken with subsequent IDE or JDK releases. But it's a very old document written in 2010, maybe now it has resolved the problem, so I want to know if Lombok will support Java 9 and does it still use the non

Does Project Lombok support Java 9?

蹲街弑〆低调 提交于 2019-12-29 04:08:21
问题 I have used Lombok in my project, but my colleague do not agree to use it, and his reason is (from controversy of lombok documents) Both of these pieces of Project Lombok make use of non-public APIs to accomplish their sorcery. This means that there is a risk that Project Lombok will be broken with subsequent IDE or JDK releases. But it's a very old document written in 2010, maybe now it has resolved the problem, so I want to know if Lombok will support Java 9 and does it still use the non

SpringBoot基础教程2-1-3 异常处理规范

邮差的信 提交于 2019-12-26 11:04:29
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 1. 概述 异常处理 ,在平时业务处理中不可避免;但是,阅读代码最头疼的就是看到一堆 try-catch 语句,业务逻辑参杂其中,极难维护;那要怎样优雅的处理异常呢?请耐心阅读全文。 2. 不负责任的处理异常 直接抛出异常或遗漏未捕获异常,会怎样?Spring Boot提供了一个默认的映射:/error,当处理中抛出异常之后,会转到该请求中处理,并且该请求有一个全局的错误页面用来展示异常内容 @RestController public class BadExceptionController { @GetMapping("/bad") public String bad(){ // todo 业务逻辑 Object object = null; // 模拟空指针异常 object.toString(); return "success"; } } 上述代码极不负责,看看测试结果 当调用者看到这个结果,估计一脸懵 3. 丑陋的异常处理 常见的异常处理,在 try-catch 块中,手动封装返回对应结果;该方法相比上面,虽然封装了异常,但是异常处理逻辑,嵌在业务逻辑中,当要修改业务逻辑时,也不可避免的新增对于异常处理逻辑,耦合度非常高 @RestController public class

Nested Target in MapStruct (Using Lombok) not working fluently

て烟熏妆下的殇ゞ 提交于 2019-12-24 19:16:19
问题 I am trying to use Mapstruct to do some nested mapping and with Lombok. As according to their latest specification mapstruct 1.2 works out of the box with Lombok. Here is my code: Source Classes @Builder @Getter @Setter public class PojoA { private String stringA; private int integer; private PojoB pojoB; } @Builder @Getter @Setter public class PojoB { private long aLong; private String string; private PojoC pojoC; } @Builder @Getter @Setter public class PojoC { private int value; } Target