[英]NiFI :- Failed to create Extension Definition for CONTROLLER_SERVICE org.apache.nifi.record.sink.lookup.RecordSinkServiceLookup
I'm trying to use DBCPConnectionPool service in my custom processor.我正在尝试在我的自定义处理器中使用 DBCPConnectionPool 服务。 So, how to use in-built controller services (which are already available on NiFi) in our custom processors.
那么,如何在我们的自定义处理器中使用内置控制器服务(NiFi 上已经提供)。
Here are my properties in *-nar/->pom.xml这是我在 *-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>
Here are my dependencies in *processors/->pom.xml这是我在 *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>
And here is my propertydescriptor for DBCPConnetionPool service :-这是我的 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();
and in my OnTrigger method I didn't used it as :-在我的 OnTrigger 方法中,我没有将其用作:-
DBCPService DBCPService = context.getProperty(DBCPConnectionPool_SERVICE)
.asControllerService(DBCPService.class);
Connection con = DBCPService.getConnection();
and was trying to use this con object as in regular passion createStatement->executeQuery.并试图在常规热情 createStatement->executeQuery 中使用此 con 对象。
When I tried to package it using mvn clean install
it started throwing error as : A required class was missing while executing org.apache.nifi:nifi-nar-maven-plugi n:1.3.1:nar: org/apache/nifi/record/sink/RecordSinkService then I added the following dependencies in processors/->pom.xml当我尝试使用
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>
This time it was new error as :- Failed to create Extension Definition for CONTROLLER_SERVICE org.apache.nifi.record.sink.lookup.RecordSinkServiceLookup: Null PointerException这次是新错误:-无法为 CONTROLLER_SERVICE org.apache.nifi.record.sink.lookup.RecordSinkServiceLookup 创建扩展定义:Null PointerException
I also checked by commenting out code which I have written, to check the way I'm using that property was wrong but, even that didn't worked.:-我还通过注释掉我编写的代码来检查,以检查我使用该属性的方式是错误的,但是,即使这样也没有用。:-
DBCPService DBCPService = context.getProperty(DBCPConnectionPool_SERVICE)
.asControllerService(DBCPService.class);
Connection con = DBCPService.getConnection();
Can someone help me out in order to use DBCPConnectionPoolService controller service in my custom processor?有人可以帮我在我的自定义处理器中使用 DBCPConnectionPoolService 控制器服务吗?
I had the same issues the other day and I solved it by using AbstractControllerService
instead of DBCPConnectionPool
therefore not needing org.apache.nifi.dbcp.DBCPService
anymore.前几天我遇到了同样的问题,我通过使用
AbstractControllerService
而不是DBCPConnectionPool
解决了它,因此不再需要org.apache.nifi.dbcp.DBCPService
。 Therefore my code would look like this:因此我的代码看起来像这样:
MyService DBCPService = context.getProperty(DBCPConnectionPool_SERVICE)
.asControllerService(MyService.class);
Connection con = DBCPService.getConnection();
MyService is the custom interface that extends ControllerService.(you have to use it when you also define the PropertyDescriptor DBCPConnectionPool_SERVICE
) MyService 是扩展 ControllerService 的自定义接口。(在定义
PropertyDescriptor DBCPConnectionPool_SERVICE
时必须使用它)
And StandardMyService
the class that extends AbstractControllerService
and implements MyService
and getConnection()
from it. StandardMyService
是扩展AbstractControllerService
并从中实现MyService
和getConnection()
的类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.