Spring Profiles — Spring Technical Interview Questions & Answers

Environment-specific beans and configuration with @Profile.

Spring Profiles

  • Profiles let one codebase use different settings for dev, test, and prod.
  • Files: application-dev.properties, application-prod.properties.
  • Activate with spring.profiles.active=dev (env var, IDE, or command line).
  • @Profile("dev") can also turn specific beans on only in that environment.
  • Running prod with dev credentials by wrong active profile.
  • Profiles = environment-specific config and beans.

Technical Interview Tip: Explain activation + one profile-specific property file.

Code Examples for Spring Profiles

Spring Profiles — working example

# application.properties
server.port=8081
spring.application.name=gocareergo
spring.profiles.active=dev
spring.datasource.url=jdbc:h2:mem:prep
app.welcome=Hello

# application-dev.properties
# logging.level.root=DEBUG

# application.yml equivalent:
# server:
#   port: 8081
# spring:
#   profiles:
#     active: dev

Spring Profiles — externalized config + profiles let one artifact run in dev/stage/prod with different values.

How to Explain Spring Profiles to an Interviewer

What is Profiles (sb)?

Used for a short Profiles sb example a small REST app Not just the heading

Give one small example of Profiles (sb).

the smallest Profiles sb example you can type Environment-specific beans and configuration with @Profile

What mistake do beginners make with Profiles (sb)?

only saying “Profiles sb” with no example Show the fix

Where do you use Profiles (sb)?

a small REST app a short Profiles sb example