What are the most common SpringBoot component registrations for Java programmers?
Many programmers in the process of development may encounter SpringBoot component registration this problem, so SpringBoot in the end have those component registration? Today I will share with you several ways to register the SpringBoot component, hoping to help you quickly solve the current problem.
├─ Java │ ├─ Java │ ├─ Java │ ├─ Java │ ├─ Java │ ├─ Java │ ├─ entity │ ├─ Java │ ├─ Java │ ├─ entity │ ├ ─ Java │ ├ ─resources ├.properties beans.xml project. Text beans.xml (├ ─ Java)
Demo2Application (Start program) Package com.example. Demo2; import com.example.demo2.entity.Stu; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.ImportResource; @importResource (locations = “classpath:/beans.xml”) public class Demo2Application {public static void main (String [] args) {/ / use ConfigurableApplicationContext context can get Beans ConfigurableApplicationContext context = SpringApplication.run(Demo2Application.class, args); Stu stu = context.getBean(“stu”, Stu.class); System.out.println(stu.toString()); / / the context type is org. Springframework. Context. The annotation. AnnotationConfigApplicationContext System.out.println(context.getClass().getName()); context.close(); }} ClassPathXmlApplicationContext ConfigurableApplicationContext relationships
Conclusions: 1. Advantage: You can specify XML files for previous project migrations 2. Problem: XML configuration is redundant and complex, now based on annotations and JDKConfig 3. Extension: Beans view in IDEA shows the icon as
I reply to “Architecture Information” to receive a full set of architecture learning materials free of charge