Spring Boot

Profiles และ Environment

Spring profiles (@Profile), application-{profile}.properties, การเปิดใช้งาน profile, ตัวแปรสภาพแวดล้อม

20 คำถามสัมภาษณ์·
Mid-Level
1

annotation @Profile ทำอะไรได้บ้างใน Spring?

คำตอบ

annotation @Profile ช่วยให้สามารถกำหนดเงื่อนไขการเปิดใช้งาน bean หรือการตั้งค่าตาม profile ที่เปิดใช้งานอยู่ เมื่อ profile หนึ่งเปิดใช้งานอยู่ (ผ่าน spring.profiles.active) เฉพาะ bean ที่ถูก annotation ด้วย profile นั้นเท่านั้นที่จะถูกโหลดเข้าสู่ Spring context สิ่งนี้ทำให้มีการตั้งค่าที่แตกต่างกันสำหรับ dev, test และ production โดยไม่ต้องเขียนโค้ดซ้ำ เช่น ใช้ฐานข้อมูล H2 ใน dev และ PostgreSQL ใน production

2

พร็อพเพอร์ตี้ใดเปิดใช้งาน profile ของ Spring Boot เมื่อแอปพลิเคชันเริ่มทำงาน?

คำตอบ

พร็อพเพอร์ตี้ spring.profiles.active เปิดใช้งาน profile หนึ่งหรือหลายตัวเมื่อเริ่มทำงาน สามารถกำหนดได้ใน application.yml, ผ่าน command line (--spring.profiles.active=prod) หรือผ่านตัวแปรสภาพแวดล้อม พร็อพเพอร์ตี้นี้เป็นวิธีมาตรฐานในการเลือกสภาพแวดล้อมการทำงาน (dev, test, prod)

3

ตั้งชื่อไฟล์การตั้งค่าเฉพาะสำหรับ profile 'production' อย่างไร?

คำตอบ

ไฟล์การตั้งค่าเฉพาะ profile จะเป็นไปตามรูปแบบ application-{profile}.yml หรือ application-{profile}.properties สำหรับ profile 'production' ไฟล์จะเป็น application-production.yml ไฟล์เหล่านี้จะเขียนทับพร็อพเพอร์ตี้ของไฟล์ application.yml หลักเมื่อ profile ที่เกี่ยวข้องเปิดใช้งานอยู่

4

ความแตกต่างระหว่าง spring.profiles.active และ spring.profiles.include คืออะไร?

5

อินเทอร์เฟซ Environment ใน Spring คืออะไร?

+17 คำถามสัมภาษณ์

หัวข้อสัมภาษณ์ Spring Boot อื่นๆ

Spring Core - IoC & DI

Junior
22 คำถาม

Spring Boot Auto-Configuration

Junior
20 คำถาม

Spring Boot Starters

Junior
18 คำถาม

Application Properties & YAML

Junior
16 คำถาม

การทำ Logging ด้วย SLF4J และ Logback

Junior
20 คำถาม

Spring Boot DevTools

Junior
15 คำถาม

Spring MVC Basics

Mid-Level
20 คำถาม

Spring REST Controllers

Mid-Level
20 คำถาม

Request & Response Handling

Mid-Level
20 คำถาม

การจัดการข้อยกเว้น

Mid-Level
25 คำถาม

Bean Validation

Mid-Level
25 คำถาม

พื้นฐาน Spring Data JPA

Mid-Level
25 คำถาม

เอนทิตี JPA และความสัมพันธ์

Mid-Level
30 คำถาม

การสืบค้น JPA

Mid-Level
30 คำถาม

Spring Data Repositories

Mid-Level
25 คำถาม

พื้นฐาน Spring Security

Mid-Level
25 คำถาม

Spring Boot Actuator

Mid-Level
20 คำถาม

การทดสอบหน่วยด้วย JUnit และ Mockito

Mid-Level
30 คำถาม

การทดสอบ Spring Boot

Mid-Level
30 คำถาม

RestTemplate และ WebClient

Mid-Level
24 คำถาม

Async และ Scheduling

Mid-Level
25 คำถาม

Caching ด้วย Spring

Mid-Level
25 คำถาม

Spring WebFlux (Reactive)

Mid-Level
25 คำถาม

ทรานแซกชัน Spring

Senior
30 คำถาม

การยืนยันตัวตนและการให้สิทธิ์ขั้นสูง

Senior
30 คำถาม

JWT และความปลอดภัยแบบ Stateless

Senior
20 คำถาม

OAuth2 และ Authorization Server

Senior
20 คำถาม

Spring Boot และ Docker

Senior
19 คำถาม

Microservices ด้วย Spring

Senior
25 คำถาม

Spring Cloud Config

Senior
19 คำถาม

การเพิ่มประสิทธิภาพการทำงาน

Senior
30 คำถาม

GraalVM Native Images

Senior
20 คำถาม

เชี่ยวชาญ Spring Boot สำหรับการสัมภาษณ์ครั้งถัดไป

เข้าถึงคำถามทั้งหมด flashcards แบบทดสอบเทคนิค แบบฝึกหัด code review และตัวจำลองสัมภาษณ์

เริ่มใช้ฟรี