![](/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.