Spring Application Download

I am new to Spring boot application. I wanted to understand how the Spring boot application creates beans without the @Configuration class. I looked at an example project in which there were neither @Bean definitions, nor component scans, but @Autowired, subject to the class dependency. Please view the snippet below:

@RestController public class RestController{ **@Autowired public CertificationService certificationService;** . . . . } //Interface public interface CertificationService{ public List<Certification> findAll(); } //Implementation Class @Transactional @Service public class CertificationServiceImpl{ public List<Certification> findAll(){ . . } } 

My limited knowledge of springs tells me that when there is an @Service annotation over a class, there should be an @ComponentScan somewhere to create a bean. But without scanning the components, how is the CertificationServiceImpl bean created, and does the CertificationService outsourcing in the RestController work here?

+8
java spring spring-boot
source share
1 answer

As the documentation said :

... The @SpringBootApplication annotation @SpringBootApplication equivalent to using @Configuration , @EnableAutoConfiguration and @ComponentScan ...

Let's say you have a Spring application class to download:

 package com.mypackage; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class SpringBootApplication { public static void main(String[] args) { SpringApplication.run(SpringBootApplication.class, args); } } 

Then, all packages below com.mypackage will be scanned by default for Spring components. By the way, you can specify packages for scanning directly in the @SpringBootApplication annotation without using @ComponentScan . More details here .

+7
source share

All Articles