Spring Configuration and StereoTypes
Spring Configuration Options
- XML Based Configuration
- Introduced in Spring Framework 2.0
- Still supported in Spring 5.x
- Common in legacy applications
- Annotation Based Configuration
- Introduced in Spring 3.0
- Picked up via 'Component Scans'
- Refers to class level annotaions
- @Controller, @Service, @Component, @Repository, etc.
- Java Based Configurations
- Introduced in Spring 3.0
- Uses java classes to define Spring Beans
- Configuration classes are defined with @Configuration
- Beans (components) are defined with @Bean
- Groovy Bean Definition DSL Configuration
- Introduced in Spring 4.0
- Allows you to declare beans in Groovy
- Borrowed from Grails
Use one or a combination of the above. They will work seemlessly together to define beans in the Spring Context The industry tends to favor Java based config
Spring Framework Sterotypes
Spring Sterotypes are used to define Spring beans in the Spring context
Available Stereotypes: @Component, @Controller, @RestController, @Repository, @Service
- Everything inherits from Component
- Repository means it dealing with the data layer
Repository is cool because Spring will detect platform specific persistence exceptions and re-throw them as Spring exceptions
No Comments