diff --git a/nifi-registry/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/db/DataSourceFactory.java b/nifi-registry/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/db/DataSourceFactory.java index a25a33e73d..2e1a9e11aa 100644 --- a/nifi-registry/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/db/DataSourceFactory.java +++ b/nifi-registry/nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/db/DataSourceFactory.java @@ -22,7 +22,7 @@ import org.apache.nifi.registry.properties.NiFiRegistryProperties; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.jdbc.DataSourceBuilder; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -34,7 +34,7 @@ import javax.sql.DataSource; * Overriding Spring Boot's normal automatic creation of a DataSource in order to use the properties * from NiFiRegistryProperties rather than the standard application.properties/yaml. */ -@ConditionalOnProperty("nifi.registry.db.url") +@ConditionalOnMissingBean(DataSource.class) @Configuration public class DataSourceFactory { diff --git a/nifi-registry/nifi-registry-core/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/DatabaseTestApplication.java b/nifi-registry/nifi-registry-core/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/DatabaseTestApplication.java index 4d94bd47d0..dde331e97e 100644 --- a/nifi-registry/nifi-registry-core/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/DatabaseTestApplication.java +++ b/nifi-registry/nifi-registry-core/nifi-registry-framework/src/test/java/org/apache/nifi/registry/db/DatabaseTestApplication.java @@ -21,6 +21,8 @@ import org.mockito.Mockito; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.FilterType; /** * Sets up the application context for database repository tests. @@ -31,6 +33,12 @@ import org.springframework.context.annotation.Bean; * The DataSourceFactory is excluded so that Spring Boot will load an in-memory H2 database. */ @SpringBootApplication +@ComponentScan( + excludeFilters = { + @ComponentScan.Filter( + type = FilterType.ASSIGNABLE_TYPE, + value = DataSourceFactory.class) + }) public class DatabaseTestApplication { public static void main(String[] args) { diff --git a/nifi-registry/nifi-registry-core/nifi-registry-web-api/src/test/java/org/apache/nifi/registry/NiFiRegistryTestApiApplication.java b/nifi-registry/nifi-registry-core/nifi-registry-web-api/src/test/java/org/apache/nifi/registry/NiFiRegistryTestApiApplication.java index ff65bb2348..effa324acd 100644 --- a/nifi-registry/nifi-registry-core/nifi-registry-web-api/src/test/java/org/apache/nifi/registry/NiFiRegistryTestApiApplication.java +++ b/nifi-registry/nifi-registry-core/nifi-registry-web-api/src/test/java/org/apache/nifi/registry/NiFiRegistryTestApiApplication.java @@ -16,6 +16,7 @@ */ package org.apache.nifi.registry; +import org.apache.nifi.registry.db.DataSourceFactory; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; import org.springframework.context.annotation.ComponentScan; @@ -29,6 +30,9 @@ import java.util.TimeZone; @ComponentScan.Filter( type = FilterType.ASSIGNABLE_TYPE, value = SpringBootServletInitializer.class), // Avoid loading NiFiRegistryApiApplication + @ComponentScan.Filter( + type = FilterType.ASSIGNABLE_TYPE, + value = DataSourceFactory.class), // Avoid loading DataSourceFactory }) public class NiFiRegistryTestApiApplication extends SpringBootServletInitializer { diff --git a/nifi-registry/nifi-registry-core/nifi-registry-web-api/src/test/java/org/apache/nifi/registry/SecureLdapTestApiApplication.java b/nifi-registry/nifi-registry-core/nifi-registry-web-api/src/test/java/org/apache/nifi/registry/SecureLdapTestApiApplication.java index 4f75592b69..5fe78e4b1f 100644 --- a/nifi-registry/nifi-registry-core/nifi-registry-web-api/src/test/java/org/apache/nifi/registry/SecureLdapTestApiApplication.java +++ b/nifi-registry/nifi-registry-core/nifi-registry-web-api/src/test/java/org/apache/nifi/registry/SecureLdapTestApiApplication.java @@ -16,6 +16,7 @@ */ package org.apache.nifi.registry; +import org.apache.nifi.registry.db.DataSourceFactory; import org.apache.nifi.registry.security.authorization.AuthorizerFactory; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; @@ -29,6 +30,9 @@ import org.springframework.context.annotation.FilterType; @ComponentScan.Filter( type = FilterType.ASSIGNABLE_TYPE, value = SpringBootServletInitializer.class), // Avoid loading NiFiRegistryApiApplication + @ComponentScan.Filter( + type = FilterType.ASSIGNABLE_TYPE, + value = DataSourceFactory.class), // Avoid loading DataSourceFactory @ComponentScan.Filter( type = FilterType.ASSIGNABLE_TYPE, value = AuthorizerFactory.class), // Avoid loading AuthorizerFactory.getAuthorizer(), as we need to add it again with test-specific @DependsOn annotation