![](/img/trans.png)
[英]org.apache.nifi.bootstrap.Command Apache NiFi is not running
[英]NiFI :- Failed to create Extension Definition for CONTROLLER_SERVICE org.apache.nifi.record.sink.lookup.RecordSinkServiceLookup
我正在尝试在我的自定义处理器中使用 DBCPConnectionPool 服务。 那么,如何在我们的自定义处理器中使用内置控制器服务(NiFi 上已经提供)。
这是我在 *-nar/->pom.xml 中的属性
<dependencies>
<dependency>
<groupId>org.sample.com</groupId>
<artifactId>nifi-customprocessor-processors</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-standard-services-api-nar</artifactId>
<version>1.14.0</version>
<type>nar</type>
</dependency>
</dependencies>
这是我在 *processors/->pom.xml 中的依赖项
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-utils</artifactId>
<version>1.14.0</version>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-mock</artifactId>
<version>1.14.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-dbcp-service</artifactId>
<version>1.14.0</version>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-dbcp-service-api</artifactId>
<version>1.14.0</version>
</dependency>
这是我的 DBCPConnetionPool 服务的属性描述符:-
public static final PropertyDescriptor DBCPConnectionPool_SERVICE = new PropertyDescriptor.Builder()
.name("DBCPConnectionPoolLookup Service")
.description("The Controller Service to use in order to establish a connection")
.required(true)
.dynamic(true)
.identifiesControllerService(DBCPService.class)
.addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
.build();
在我的 OnTrigger 方法中,我没有将其用作:-
DBCPService DBCPService = context.getProperty(DBCPConnectionPool_SERVICE)
.asControllerService(DBCPService.class);
Connection con = DBCPService.getConnection();
并试图在常规热情 createStatement->executeQuery 中使用此 con 对象。
当我尝试使用mvn clean install
打包它时,它开始抛出错误:执行 org.apache.nifi:nifi-nar-maven-plugin:1.3.1:nar:org/apache/nifi/ 时缺少所需的类record/sink/RecordSinkService然后我在处理器/-> pom.xml 中添加了以下依赖项
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-record-sink-service</artifactId>
<version>1.14.0</version>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-record-sink-api</artifactId>
<version>1.14.0</version>
</dependency>
这次是新错误:-无法为 CONTROLLER_SERVICE org.apache.nifi.record.sink.lookup.RecordSinkServiceLookup 创建扩展定义:Null PointerException
我还通过注释掉我编写的代码来检查,以检查我使用该属性的方式是错误的,但是,即使这样也没有用。:-
DBCPService DBCPService = context.getProperty(DBCPConnectionPool_SERVICE)
.asControllerService(DBCPService.class);
Connection con = DBCPService.getConnection();
有人可以帮我在我的自定义处理器中使用 DBCPConnectionPoolService 控制器服务吗?
前几天我遇到了同样的问题,我通过使用AbstractControllerService
而不是DBCPConnectionPool
解决了它,因此不再需要org.apache.nifi.dbcp.DBCPService
。 因此我的代码看起来像这样:
MyService DBCPService = context.getProperty(DBCPConnectionPool_SERVICE)
.asControllerService(MyService.class);
Connection con = DBCPService.getConnection();
MyService 是扩展 ControllerService 的自定义接口。(在定义PropertyDescriptor DBCPConnectionPool_SERVICE
时必须使用它)
StandardMyService
是扩展AbstractControllerService
并从中实现MyService
和getConnection()
的类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.