İlkay Gunel
İlkay Gunel

Reputation: 852

Spring Boot Conditional Resource Importing

We can import an XML resource in Spring Boot project like this:

@ImportResource("${locationProperty:defaultLocation}")

But I need to import this file according to a condition. Such as, if a property value is false, it shouldn't import this file, it it's true, it should import.

How can I conditionally import a resource in Spring Boot application?

Upvotes: 0

Views: 1881

Answers (1)

Dirk Deyne
Dirk Deyne

Reputation: 6936

You can use ConditionalOnProperty

Something like:

@Configuration
@ConditionalOnProperty(prefix = "beans", name = "additional")
@ImportResource("${path-to-bean-config}")
public class AdditionalXmlBeans{
}

Upvotes: 2

Related Questions