创建一个Hello类,采用@Component注解

HelloApp类,采用@ComponentScan注解

运行结果

2.Student和Phone的例子改成注解实现
Lombok插件的使用
File->Settings->plugins,搜索Lombok,安装,重启IDEA

添加依赖

使用@Data注解,简化POJO类,不用再写那些构造方法、getter/setter,toString()了,专注定义属性。
Student类

Phone类

StudentApp类

运行结果

注释
@Data
@Setter
@Getter
@Log4j
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode
@NonNull
@Cleanup
@ToString
@RequiredArgsConstructor
@Value
@SneakyThrows
@Synchronized
。
网友评论