Spring Configuration Options

  • Spring beans are picked up by 'Component Scans'
    • The refers to the class level annotation
    • When a SpringBoot app does a component scan, it looks at that package and down.
  • Class level annotation: @Controller, @Service...etc

Spring Stereotypes

  • Spring Stereotypes are used to defined Spring Beans in the Spring Context
  • Stereotypes availables:
    • @Controller
    • @RestController
    • @Component
    • @Service
    • @Repository

These are used to express the intent.

Annotation Description
@Component Indicates that an annotated class is a 'component' and it will be created as a bean
@Repository Works exactly the same as @Component but it is used to express the intent that it is a Database Layer
@Service Works exactly the same as @Component but it is used to express the intent that it is a Service Layer
@Controller Indicates that an annotated class has the roles of a Spring MVC "Controller"
@RestController Convenience Annotation which extends @Controller and adds @ResponseBody - @ResponseBody is used to convert Java Objects into Json/XML

Component Scan

  • Component Scan is a way for Spring to look at your package structure and find Spring Beans. \
  • It will look for classes annotated with Spring Annotation eg @Service..etc

@SpringBootAnnotation

Includes the following:

    • @Configuration - Declares class as Spring Configuration
    • @EnableAutoConfiguration - Enable auto configuration
    • @Component Scan - Scans for components in current package and all child packages

https://stackoverflow.com/questions/35005158/what-is-the-difference-between-componentscan-and-enableautoconfiguration-in-sp

results matching ""

    No results matching ""