Skip to content

Instantly share code, notes, and snippets.

@j-tim
Created September 29, 2019 18:50
Show Gist options
  • Save j-tim/47513968efb8db809497fcce2821f4b7 to your computer and use it in GitHub Desktop.
Save j-tim/47513968efb8db809497fcce2821f4b7 to your computer and use it in GitHub Desktop.
Service class annotation with @lazy (Since Spring Framework 5.2 and Spring Boot 2.2) to enable lazy bean initialization
package nl.jtim.spring.boot.lazy;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
@Service
@Lazy
@Slf4j
public class LazyInitializedService {
@PostConstruct
public void afterBeanInitialized() {
log.info("Bean 'LazyInitializedService' initialized...");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment