Spring Boot

Profiles & Environment

Spring profiles (@Profile), application-{profile}.properties, profile activation, environment variables

20 câu hỏi phỏng vấn·
Mid-Level
1

What does the @Profile annotation allow in Spring?

Câu trả lời

The @Profile annotation allows conditional bean or configuration activation based on active profiles. When a profile is active (via spring.profiles.active), only beans annotated with that profile are loaded into the Spring context. This enables different configurations for dev, test and production without code duplication. For example, using H2 database in dev and PostgreSQL in production.

2

Which property activates a Spring Boot profile at application startup?

Câu trả lời

The spring.profiles.active property activates one or more profiles at startup. It can be defined in application.yml, via command line (--spring.profiles.active=prod), or through environment variables. This property is the standard method for selecting the execution environment (dev, test, prod).

3

How to name a configuration file specific to the 'production' profile?

Câu trả lời

Profile-specific configuration files follow the pattern application-{profile}.yml or application-{profile}.properties. For the 'production' profile, the file will be application-production.yml. These files override properties from the main application.yml when the corresponding profile is active.

4

What is the difference between spring.profiles.active and spring.profiles.include?

5

What is the Environment interface in Spring?

+17 câu hỏi phỏng vấn

Nắm vững Spring Boot cho lần phỏng vấn tiếp theo

Truy cập tất cả câu hỏi, flashcards, bài kiểm tra kỹ thuật, bài tập code review và mô phỏng phỏng vấn.

Bắt đầu miễn phí