Broadcom conceptsSpring Professional DevelopSpring Core
2V0-72.22 Spring Core: what the Spring exam tests
What the Spring Professional Develop exam asks about Spring Core: @Bean and @Configuration rules, component scanning, lifecycle callbacks and Spring AOP.
3 min read
A bean declared with @Bean is named after its method by default. And because Spring AOP is proxy-based, a call from one method to another inside the same object is not intercepted.
01 What does the Spring Professional Develop exam test about Spring Core?
You reread your Spring Core notes before a mock, and every page says bean. Split them into three areas: Java configuration, component scanning and Spring AOP.
Three areas of Spring Core and what to know in each
- Java configurationHow @Bean methods are named, scoped and wired.
- Component scanningWhich classes are detected, and how they are named.
- Spring AOPWhich join points and designators Spring supports.
Java-based configuration rests on @Configuration, @Bean, @Import and @DependsOn.
02 How do @Configuration and @Bean define beans?
Start with Java configuration. A @Bean bean is a singleton by default, which @Scope can override.
Inside a @Configuration class, one @Bean method can call another to wire a dependency; in a plain @Component class it cannot. That works because each @Configuration class is subclassed with CGLIB at startup, so it must not be final.
@Bean methods in a @Configuration class and in a @Component class
@Configuration class
- Holds @Bean methods
- Subclassed with CGLIB at startup
- @Bean methods can call each other
@Component class
- Holds @Bean methods
- No inter-bean method calls
Inter-bean method calls work only in @Configuration classes.
03 What does component scanning pick up?
Next come the beans you never declare by hand. By default, scanning detects only classes marked @Component, @Repository, @Service, @Controller, @Configuration, or a custom annotation that carries @Component.
A detected bean with no explicit name gets its uncapitalized simple class name. Its @PostConstruct and @PreDestroy methods run once CommonAnnotationBeanPostProcessor is registered.
@Repository, @Service and @Controller are specializations of @Component.
04 What can Spring AOP intercept?
Finally, add behavior around those beans. Spring AOP supports only method execution join points on Spring beans.
Designators such as call, get, set or cflow throw an IllegalArgumentException, while Spring adds its own bean designator. In an execution pattern, () matches no parameters, (..) zero or more, and (*) exactly one.
Calls within the target object bypass the proxy, so they are not intercepted.
Summary
- @Bean methods can call each other only inside @Configuration classes.
- Scanned beans without a name get the uncapitalized class name.
- Spring AOP intercepts only method execution on Spring beans.
Sources
- Using the @Configuration annotation :: Spring Framework (opens in a new tab)
- Classpath Scanning and Managed Components :: Spring Framework (opens in a new tab)
- Declaring a Pointcut :: Spring Framework (opens in a new tab)
- Using the @Bean Annotation :: Spring Framework (opens in a new tab)
- Container Overview :: Spring Framework (opens in a new tab)
- Using @PostConstruct and @PreDestroy :: Spring Framework (opens in a new tab)