mdoTomofumi Chiba
8/9/2023, 9:27:06 AM

Spring Tips

Immutable な constructor injection がお勧めです。

@Service
public class FooService {
    @Autowired
    private BarRepository barRepository;
}

↓ 修正

@Service
public class FooService {
    private final BarRepository barRepository;
    public FooService(BarRepository barRepository) {
        this.barRepository = barRepository;
    }
}

↓ Lombok でコードを減らす。

@Service
@RequiredArgsConstructor
public class FooService {
    private final BarRepository barRepository;
}
TweetBlueskyLike