Lombok在spring中的特殊注解 @RequiredArgsConstructor

将Lombok之前先了解一下spring的注入方式

一:目前使用最广泛的 @Autowired

@Service
public class BaseInfoCompanyFareServiceImpl implements BaseInfoCompanyFareService {

    @Autowired
    private BaseInfoCompanyFareDao baseInfoCompanyFareDao;
    @Autowired
    private BaseInfoCompanyDao baseInfoCompanyDao;
}

二:构造器注入

@Service
public class BaseInfoCompanyPayServiceImpl implements BaseInfoCompanyPayService {

    private final BaseInfoCompanyPayDao baseInfoCompanyPayDao;

    public BaseInfoCompanyPayServiceImpl(BaseInfoCompanyPayDao baseInfoCompanyPayDao) {
        this.baseInfoCompanyPayDao = baseInfoCompanyPayDao;
    }
}

三:lombok提供的@RequiredArgsConstructor方式

@Service
@RequiredArgsConstructor
public class BaseInfoCompanyServiceImpl implements BaseInfoCompanyService {

    final BaseInfoCompanyDao baseInfoCompanyDao;
    final BaseInfoCompanyServiceDao baseInfoCompanyServiceDao;
}

 

 

 

 

posted @ 2020-10-30 13:48  ch3ny  阅读(18345)  评论(0编辑  收藏  举报