Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
IT Security Nachrichten7 AI Security Best Practices For Deploying Generative AI In Cyber Teams(23.09.2026 um 11:31 Uhr)
IT Security NachrichtenEssential AI Security Trends Shaping Cyber Defense Strategies(23.09.2026 um 11:35 Uhr)
IT Security NachrichtenHow AI-Powered Threat Detection Catches What Traditional Tools Miss(23.09.2026 um 11:39 Uhr)
IT Security NachrichtenAI Security Guidelines And Frameworks Enterprises Need To Be Aware Of(23.09.2026 um 11:46 Uhr)
IT Security NachrichtenWhat Are the Main Security Risks Associated With Generative AI?(23.09.2026 um 11:51 Uhr)
IT Security NachrichtenHow Is GenAI Transforming Cybersecurity Strategies?(23.09.2026 um 11:53 Uhr)
IT Security NachrichtenCan AI Be Used To Effectively Prevent Cyberattacks?(23.09.2026 um 11:58 Uhr)
IT Security NachrichtenAre There Any Government Policies On Using AI For Cybersecurity?(23.09.2026 um 12:00 Uhr)
IT Security Nachrichten7 AI Security Best Practices For Deploying Generative AI In Cyber Teams(23.09.2026 um 11:31 Uhr)
IT Security NachrichtenEssential AI Security Trends Shaping Cyber Defense Strategies(23.09.2026 um 11:35 Uhr)
IT Security NachrichtenHow AI-Powered Threat Detection Catches What Traditional Tools Miss(23.09.2026 um 11:39 Uhr)
IT Security NachrichtenAI Security Guidelines And Frameworks Enterprises Need To Be Aware Of(23.09.2026 um 11:46 Uhr)
IT Security NachrichtenWhat Are the Main Security Risks Associated With Generative AI?(23.09.2026 um 11:51 Uhr)
IT Security NachrichtenHow Is GenAI Transforming Cybersecurity Strategies?(23.09.2026 um 11:53 Uhr)
IT Security NachrichtenCan AI Be Used To Effectively Prevent Cyberattacks?(23.09.2026 um 11:58 Uhr)
IT Security NachrichtenAre There Any Government Policies On Using AI For Cybersecurity?(23.09.2026 um 12:00 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

Validating Configuration Properties in Spring Boot Application Startup

The @ConfigurationProperties annotation in Spring Boot is used to bind configuration parameters typically from properties or YAML files to a Java class. But, did you know you also can validate configuration properties at spring…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

The @ConfigurationProperties annotation in Spring Boot is used to bind configuration parameters typically from properties or YAML files to a Java class.



But, did you know you also can validate configuration properties at spring application startup with the @ConfigurationProperties annotation? Let's dive in!







Let's say we have a Spring boot importer service that imports customer data from a CSV file to the database periodically. For the importer to work we have the following configurations:




importer:  
service:
filePath: '/nfs/files'
fileType: '.xslx'
threadPoolSize: 3






These properties can be mapped to a Java class automatically using @ConfigurationProperties annotation as follows:




@Getter 
@Setter
@Component
@ConfigurationProperties(prefix = "importer.service")
public class ImporterConfig {
String filePath;
String fileType;
int threadPoolSize;
}






Now let's say, we want to ensure the importer configuration is provided and meets the validation criteria when the application starts. If any of the validation fails, then the application should fail during startup.



For this validation to work, we need to have a JSR-380 implementation like Hibernate Validator on your classpath.




implementation 'org.springframework.boot:spring-boot-starter-validation'






Once we have a validator in the classpath, we need to explicitly enable the configuration properties validation using @Validated annotation.



For example,




@Getter  
@Setter
@Component
@Validated
@ConfigurationProperties(prefix = "importer.service")
public class ImporterConfig {

@NotNull
String filePath;

@NotNull
@Pattern(regexp = "\\.csv$|\\.txt$")
String fileType;

@Positive
@Max(10)
int threadPoolSize;
}






This can validate properties on application startup when used in conjunction with JSR-380 bean validation annotations such as @Max, and @NotNull. Here are some of the common annotations used for bean validation:





  • @NotNull: specifies that a property must be not null


  • @NotEmpty: specifies that a property must be not null or not empty


  • @Size: ensure that a property size is between attributes min and max


  • @Email: specifies that a property must be a valid email address


  • @AssertTrue@AssertFalse: ensure that a property value is true/false


  • @Positive@Negative: ensure that a property is positive/negative


  • @Past / @Future: specifies that the date must be in the past/ future


  • @Max / @Min: specifies that a property has a value not greater/not smaller than the value attribute



A full list of built-in validation constraints in JSR 380 can be found here.



Now, Run the application and notice that it will bind these properties from application.yaml to the ImporterConfig object and validate them at application startup, thus ensuring the application doesn't run with invalid configurations.



If the validation fails it will result in BindException as shown below:




***************************
APPLICATION FAILED TO START
***************************

Description:

Binding to target com.stacktips.app.config.ImporterConfig failed:

Property: importer.service.fileType
Value: ".xlsx"
Origin: class path resource [application.yaml] - 8:15
Reason: must match "\.csv$|\.txt$"


Action:

Update your application's configuration






Now you update the fileType: .csv and the application will start as expected.






Considerations for Using Records



Starting with Spring Boot 2.6 and Java 16 you can use record classes with @ConfigurationProperties. But there are a few things you need to consider when using records.




@Validated  
@ConfigurationProperties(prefix = "importer.service")
public record ImporterProperties(
@NotNull String filePath,
@Min(3) int threadPoolSize) {
}






The @Componenet annotation cannot be used with records. Your IDE will show an annotated with @ConstructorBinding but defined as a Spring component error.



This is because the @Component annotation is generally used to define a bean that the Spring container will automatically detect and manage. As Java records are immutable, it conflicts with the way Spring manages beans, which involves proxying, intercepting, and potentially altering object states or behaviour.



To fix this, we need to remove the @Component annotation and explicitly define the bean registration. We can either use @EnableConfigurationProperties or define the @Bean annotation in one of the @Configuration classes.



For example:




@EnableConfigurationProperties(ImporterProperties.class)  
@SpringBootApplication
public class MyApplication {

public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}

}


Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Validating Configuration Properties in Spring Boot Application Startup

Thematisch verwandte Begriffe: Validating, Configuration, Properties, Spring · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-96258 | A vulnerability has been found in onSite internet GmbH Auktion NG Auktio…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick