Profiles en Environment
Spring-profiles (@Profile), application-{profile}.properties, profile-activatie, omgevingsvariabelen
1Wat maakt de @Profile-annotatie mogelijk in Spring?
Wat maakt de @Profile-annotatie mogelijk in Spring?
Antwoord
De @Profile-annotatie maakt het mogelijk om de activatie van een bean of configuratie afhankelijk te maken van de actieve profiles. Wanneer een profile actief is (via spring.profiles.active), worden alleen de beans die met dat profile zijn geannoteerd in de Spring-context geladen. Hierdoor kun je verschillende configuraties hebben voor dev, test en productie zonder code te dupliceren. Bijvoorbeeld een H2-database gebruiken in dev en PostgreSQL in productie.
2Welke eigenschap activeert een Spring Boot-profile bij het opstarten van de applicatie?
Welke eigenschap activeert een Spring Boot-profile bij het opstarten van de applicatie?
Antwoord
De eigenschap spring.profiles.active activeert een of meer profiles bij het opstarten. Ze kan worden gedefinieerd in application.yml, via de command line (--spring.profiles.active=prod) of via een omgevingsvariabele. Deze eigenschap is de standaardmethode om de uitvoeromgeving (dev, test, prod) te selecteren.
3Hoe noem je een configuratiebestand dat specifiek is voor het profile 'production'?
Hoe noem je een configuratiebestand dat specifiek is voor het profile 'production'?
Antwoord
Profile-specifieke configuratiebestanden volgen het patroon application-{profile}.yml of application-{profile}.properties. Voor het profile 'production' is het bestand application-production.yml. Deze bestanden overschrijven de eigenschappen van het hoofdbestand application.yml wanneer het betreffende profile actief is.
Wat is het verschil tussen spring.profiles.active en spring.profiles.include?
Wat is de Environment-interface in Spring?
+17 gespreksvragen
Andere Spring Boot-sollicitatieonderwerpen
Spring Core - IoC & DI
Spring Boot Auto-Configuration
Spring Boot Starters
Application Properties & YAML
Logging met SLF4J & Logback
Spring Boot DevTools
Spring MVC Basics
Spring REST Controllers
Request & Response Handling
Uitzonderingsafhandeling
Bean Validation
Spring Data JPA-basis
JPA-entiteiten en relaties
JPA-query's
Spring Data Repositories
Spring Security Basis
Spring Boot Actuator
Unit testing met JUnit & Mockito
Spring Boot testen
RestTemplate en WebClient
Async & Scheduling
Caching met Spring
Spring WebFlux (Reactive)
Spring-transacties
Geavanceerde authenticatie en autorisatie
JWT & stateless beveiliging
OAuth2 & Authorization Server
Spring Boot en Docker
Microservices met Spring
Spring Cloud Config
Prestatie-optimalisatie
GraalVM Native Images
Beheers Spring Boot voor je volgende gesprek
Krijg toegang tot alle vragen, flashcards, technische tests, code review-oefeningen en gespreksimulatoren.
Begin gratis