mirror of https://github.com/apache/nifi.git
NIFI-12666 Corrected Registry Data Source Configuration (#8299)
This commit is contained in:
parent
89836f32d0
commit
693b187396
|
@ -22,7 +22,7 @@ import org.apache.nifi.registry.properties.NiFiRegistryProperties;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
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.boot.jdbc.DataSourceBuilder;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
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
|
* 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.
|
* from NiFiRegistryProperties rather than the standard application.properties/yaml.
|
||||||
*/
|
*/
|
||||||
@ConditionalOnProperty("nifi.registry.db.url")
|
@ConditionalOnMissingBean(DataSource.class)
|
||||||
@Configuration
|
@Configuration
|
||||||
public class DataSourceFactory {
|
public class DataSourceFactory {
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,8 @@ import org.mockito.Mockito;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.context.annotation.Bean;
|
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.
|
* 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.
|
* The DataSourceFactory is excluded so that Spring Boot will load an in-memory H2 database.
|
||||||
*/
|
*/
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
|
@ComponentScan(
|
||||||
|
excludeFilters = {
|
||||||
|
@ComponentScan.Filter(
|
||||||
|
type = FilterType.ASSIGNABLE_TYPE,
|
||||||
|
value = DataSourceFactory.class)
|
||||||
|
})
|
||||||
public class DatabaseTestApplication {
|
public class DatabaseTestApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.nifi.registry;
|
package org.apache.nifi.registry;
|
||||||
|
|
||||||
|
import org.apache.nifi.registry.db.DataSourceFactory;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
@ -29,6 +30,9 @@ import java.util.TimeZone;
|
||||||
@ComponentScan.Filter(
|
@ComponentScan.Filter(
|
||||||
type = FilterType.ASSIGNABLE_TYPE,
|
type = FilterType.ASSIGNABLE_TYPE,
|
||||||
value = SpringBootServletInitializer.class), // Avoid loading NiFiRegistryApiApplication
|
value = SpringBootServletInitializer.class), // Avoid loading NiFiRegistryApiApplication
|
||||||
|
@ComponentScan.Filter(
|
||||||
|
type = FilterType.ASSIGNABLE_TYPE,
|
||||||
|
value = DataSourceFactory.class), // Avoid loading DataSourceFactory
|
||||||
})
|
})
|
||||||
public class NiFiRegistryTestApiApplication extends SpringBootServletInitializer {
|
public class NiFiRegistryTestApiApplication extends SpringBootServletInitializer {
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.nifi.registry;
|
package org.apache.nifi.registry;
|
||||||
|
|
||||||
|
import org.apache.nifi.registry.db.DataSourceFactory;
|
||||||
import org.apache.nifi.registry.security.authorization.AuthorizerFactory;
|
import org.apache.nifi.registry.security.authorization.AuthorizerFactory;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
||||||
|
@ -29,6 +30,9 @@ import org.springframework.context.annotation.FilterType;
|
||||||
@ComponentScan.Filter(
|
@ComponentScan.Filter(
|
||||||
type = FilterType.ASSIGNABLE_TYPE,
|
type = FilterType.ASSIGNABLE_TYPE,
|
||||||
value = SpringBootServletInitializer.class), // Avoid loading NiFiRegistryApiApplication
|
value = SpringBootServletInitializer.class), // Avoid loading NiFiRegistryApiApplication
|
||||||
|
@ComponentScan.Filter(
|
||||||
|
type = FilterType.ASSIGNABLE_TYPE,
|
||||||
|
value = DataSourceFactory.class), // Avoid loading DataSourceFactory
|
||||||
@ComponentScan.Filter(
|
@ComponentScan.Filter(
|
||||||
type = FilterType.ASSIGNABLE_TYPE,
|
type = FilterType.ASSIGNABLE_TYPE,
|
||||||
value = AuthorizerFactory.class), // Avoid loading AuthorizerFactory.getAuthorizer(), as we need to add it again with test-specific @DependsOn annotation
|
value = AuthorizerFactory.class), // Avoid loading AuthorizerFactory.getAuthorizer(), as we need to add it again with test-specific @DependsOn annotation
|
||||||
|
|
Loading…
Reference in New Issue