Posts

Showing posts with the label @Import

Spring @Import Annotation Example

Image
In this section we will learn about @Import  Annotation. When we run a Spring application, the packages are scanned. Beans are created from @Component , @Service , @Repository and @Configuration classes. Scanning takes place using the @ComponentScan annotation.  It is contained inside the @SpringBootApplication annotation, with which the main class of the application is annotated. All classes that are in the same package as the class with the @ComponentScan (that is, with the @SpringBootApplication ) as well as in the subpackages of this package are scanned. If you generate a Spring Boot project on the https://start.spring.io  site, you can see: the main class with the annotation with the @SpringBootApplication is in the root package. This means that by default all classes that are below are scanned. That is, the Main Application can be in the com.knf.dev.demo package, but not in the java folder without the package. Correct Structure: The EmailNotificationService and SMSNotifica