Spring Boot Auto-Configuration
การกำหนดค่าอัตโนมัติของ Spring Boot, @SpringBootApplication, starter, bean แบบมีเงื่อนไข, spring.factories
1การกำหนดค่าอัตโนมัติใน Spring Boot คืออะไร?
การกำหนดค่าอัตโนมัติใน Spring Boot คืออะไร?
คำตอบ
การกำหนดค่าอัตโนมัติจะกำหนดค่า bean ของ Spring โดยอัตโนมัติตาม dependency ที่มีอยู่ใน classpath ตัวอย่างเช่น หากมี spring-boot-starter-data-jpa อยู่ Spring Boot จะกำหนดค่า DataSource, EntityManagerFactory และ TransactionManager โดยอัตโนมัติ สิ่งนี้ช่วยลดการกำหนดค่าด้วยตนเองที่จำเป็นได้อย่างมาก
2annotation ใดที่เปิดใช้งานการกำหนดค่าอัตโนมัติใน Spring Boot?
annotation ใดที่เปิดใช้งานการกำหนดค่าอัตโนมัติใน Spring Boot?
คำตอบ
@EnableAutoConfiguration เปิดใช้งานกลไกการกำหนดค่าอัตโนมัติของ Spring Boot annotation นี้รวมอยู่ใน @SpringBootApplication ซึ่งรวม @Configuration, @EnableAutoConfiguration และ @ComponentScan เข้าด้วยกัน โดยจะสแกน classpath เพื่อตรวจหาคลาสการกำหนดค่าอัตโนมัติ
3annotation @SpringBootApplication รวมอะไรเข้าด้วยกัน?
annotation @SpringBootApplication รวมอะไรเข้าด้วยกัน?
คำตอบ
@SpringBootApplication เป็น annotation แบบรวมที่รวม annotation สำคัญสามตัวเข้าด้วยกัน: @Configuration (ประกาศคลาสการกำหนดค่า), @EnableAutoConfiguration (เปิดใช้งานการกำหนดค่าอัตโนมัติ) และ @ComponentScan (สแกนคอมโพเนนต์ใน package ปัจจุบัน) สิ่งนี้ช่วยหลีกเลี่ยงการประกาศ annotation ทั้งสามตัวนี้แยกกัน
จะยกเว้นการกำหนดค่าอัตโนมัติเฉพาะอย่างได้อย่างไร?
@ConditionalOnClass มีจุดประสงค์อะไร?
+17 คำถามสัมภาษณ์
หัวข้อสัมภาษณ์ Spring Boot อื่นๆ
Spring Core - IoC & DI
Spring Boot Starters
Application Properties & YAML
การทำ Logging ด้วย SLF4J และ Logback
Spring Boot DevTools
Spring MVC Basics
Spring REST Controllers
Request & Response Handling
การจัดการข้อยกเว้น
Bean Validation
พื้นฐาน Spring Data JPA
เอนทิตี JPA และความสัมพันธ์
การสืบค้น JPA
Spring Data Repositories
พื้นฐาน Spring Security
Spring Boot Actuator
การทดสอบหน่วยด้วย JUnit และ Mockito
การทดสอบ Spring Boot
Profiles และ Environment
RestTemplate และ WebClient
Async และ Scheduling
Caching ด้วย Spring
Spring WebFlux (Reactive)
ทรานแซกชัน Spring
การยืนยันตัวตนและการให้สิทธิ์ขั้นสูง
JWT และความปลอดภัยแบบ Stateless
OAuth2 และ Authorization Server
Spring Boot และ Docker
Microservices ด้วย Spring
Spring Cloud Config
การเพิ่มประสิทธิภาพการทำงาน
GraalVM Native Images
เชี่ยวชาญ Spring Boot สำหรับการสัมภาษณ์ครั้งถัดไป
เข้าถึงคำถามทั้งหมด flashcards แบบทดสอบเทคนิค แบบฝึกหัด code review และตัวจำลองสัมภาษณ์
เริ่มใช้ฟรี