[JAVA-9344] Split spring-core module
This commit is contained in:
@@ -1,16 +1,15 @@
|
||||
## Spring Core
|
||||
|
||||
This module contains articles about core Spring functionality
|
||||
This module contains articles about core Spring functionality.
|
||||
|
||||
### Relevant Articles:
|
||||
|
||||
- [Introduction to Spring’s StreamUtils](https://www.baeldung.com/spring-stream-utils)
|
||||
- [A Quick Guide to the Spring @Lazy Annotation](https://www.baeldung.com/spring-lazy-annotation)
|
||||
- [BeanNameAware and BeanFactoryAware Interfaces in Spring](https://www.baeldung.com/spring-bean-name-factory-aware)
|
||||
- [Access a File from the Classpath in a Spring Application](https://www.baeldung.com/spring-classpath-file-access)
|
||||
- [Spring Application Context Events](https://www.baeldung.com/spring-context-events)
|
||||
- [What is a Spring Bean?](https://www.baeldung.com/spring-bean)
|
||||
- [Spring PostConstruct and PreDestroy Annotations](https://www.baeldung.com/spring-postconstruct-predestroy)
|
||||
- [Intro to the Spring ClassPathXmlApplicationContext](http://www.baeldung.com/spring-classpathxmlapplicationcontext)
|
||||
- More articles: [[next -->]](/spring-core-2)
|
||||
- More articles: [[next -->]](../spring-core-2)
|
||||
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
package com.baeldung.lazy;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
|
||||
@Lazy
|
||||
@Configuration
|
||||
@ComponentScan(basePackages = "com.baeldung.lazy")
|
||||
public class AppConfig {
|
||||
|
||||
@Lazy
|
||||
@Bean
|
||||
public Region getRegion(){
|
||||
return new Region();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Country getCountry(){
|
||||
return new Country();
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package com.baeldung.lazy;
|
||||
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Lazy
|
||||
@Component
|
||||
public class City {
|
||||
|
||||
public City() {
|
||||
System.out.println("City bean initialized");
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package com.baeldung.lazy;
|
||||
|
||||
public class Country {
|
||||
|
||||
public Country() {
|
||||
System.out.println("Country bean initialized");
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
package com.baeldung.lazy;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
|
||||
public class Region {
|
||||
|
||||
@Lazy
|
||||
@Autowired
|
||||
private City city;
|
||||
|
||||
public Region() {
|
||||
System.out.println("Region bean initialized");
|
||||
}
|
||||
|
||||
public City getCityInstance() {
|
||||
return city;
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
package com.baeldung.Lazy;
|
||||
|
||||
import com.baeldung.lazy.AppConfig;
|
||||
import com.baeldung.lazy.Country;
|
||||
import com.baeldung.lazy.Region;
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user