* JAVA-19555 Move articles from spring-core-5 module to spring-boot-annotations-2 module * JAVA-19555 Move articles from spring-core module to spring-boot-annotations-2 module
35 lines
1.1 KiB
Java
35 lines
1.1 KiB
Java
package com.baeldung.lazy;
|
|
|
|
import org.junit.Test;
|
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
|
|
|
public class LazyAnnotationUnitTest {
|
|
|
|
@Test
|
|
public void givenLazyAnnotation_whenConfigClass_thenLazyAll() {
|
|
// Add @Lazy to AppConfig.class while testing
|
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
|
ctx.register(AppConfig.class);
|
|
ctx.refresh();
|
|
ctx.getBean(Region.class);
|
|
ctx.getBean(Country.class);
|
|
}
|
|
|
|
@Test
|
|
public void givenLazyAnnotation_whenAutowire_thenLazyBean() {
|
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
|
ctx.register(AppConfig.class);
|
|
ctx.refresh();
|
|
Region region = ctx.getBean(Region.class);
|
|
region.getCityInstance();
|
|
}
|
|
|
|
@Test
|
|
public void givenLazyAnnotation_whenBeanConfig_thenLazyBean() {
|
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
|
ctx.register(AppConfig.class);
|
|
ctx.refresh();
|
|
ctx.getBean(Region.class);
|
|
}
|
|
}
|