NIFI-12666 Corrected Registry Data Source Configuration (#8299)

This commit is contained in:
David Handermann 2024-01-24 19:59:03 -06:00 committed by GitHub
parent 89836f32d0
commit 693b187396
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 18 additions and 2 deletions

View File

@ -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 {

View File

@ -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) {

View File

@ -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 {

View File

@ -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