Как реализовать протопоток с помощью AutoProtoSchemaBuilder для удаленного кэша Red Hat Data Grid
У меня есть приложение Java, управляемое из maven. Я реализовал кеш Data Grid с
org.infinispan.client.hotrod.RemoteCacheManager
версия 8.2 для подключения приложения к распределенной службе удаленного кеширования.
Перешел по ссылке на страницу Red Hat https://access.redhat.com/documentation/en-us/red_hat_data_grid/8.2/html/cache_encoding_and_marshalling/marshalling_user_types для реализации объекта protostream. Позвольте мне показать, как я реализовал приложение, потому что я не могу создавать автоматически через
@AutoProtoSchemaBuilder
конкретные классы, как описано в руководстве:
Реализованный пример:
файл pom.xml :
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-bom</artifactId>
<version>12.1.7.Final-redhat-00001</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-client-hotrod</artifactId>
<version>12.1.7.Final</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.infinispan/infinispan-jcache-remote -->
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-jcache-remote</artifactId>
<version>12.1.7.Final</version>
</dependency>
<dependency>
<groupId>org.infinispan.protostream</groupId>
<artifactId>protostream-processor</artifactId>
<version>4.4.1.Final</version>
<scope>provided</scope>
</dependency>
LibraryInitalizer.java Интерфейс
package com.xxx.wa.configurator.cache.protostream;
import org.infinispan.protostream.GeneratedSchema;
import org.infinispan.protostream.annotations.AutoProtoSchemaBuilder;
import com.ducati.wa.configurator.cache.protostream.test.Home;
@AutoProtoSchemaBuilder(includeClasses = { Home.class }, schemaFileName = "simple.proto", schemaFilePath = "proto/", schemaPackageName = "com.ducati.wa.configurator.cache.protostream.test")
public interface LibraryInitalizer extends GeneratedSchema{
}
Home.java как объект для тестирования
package com.xxx.wa.configurator.cache.protostream.test;
import java.io.Serializable;
import org.infinispan.protostream.annotations.ProtoFactory;
import org.infinispan.protostream.annotations.ProtoField;
public class Home implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
@ProtoField(number = 1)
String name;
@ProtoField(number = 2)
String address;
public Home() {
super();
}
@ProtoFactory
public Home(String name, String address) {
super();
this.name = name;
this.address = address;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
}
Возникшая проблема - это пропущенная автогенерация класса LibraryInitalizerImpl, которую я однажды сделал
mvn clean compile
команда maven.
В настоящее время я использую
org.apache.maven.plugins
, Вы знаете проблему автогенерации?
1 ответ
Просто, чтобы обновить мой пост.
Я узнал проблему. В плагине Maven были отключены обработчики аннотаций.
Я добавил тег для процессора protostream следующим образом:
<annotationProcessorPaths>
<annotationProcessorPath>
<groupId>org.infinispan.protostream</groupId>
<artifactId>protostream-processor</artifactId>
<version>4.4.1.Final</version>
</annotationProcessorPath>
</annotationProcessorPaths>
в
<compilerArgument>-proc:none</compilerArgument>
не разрешил обработчик аннотаций. наконец
maven-compiler-plugin
отлично работает следующее:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<!-- <configuration>
<compilerArgument>-proc:none</compilerArgument>
</configuration> -->
<configuration>
<annotationProcessorPaths>
<annotationProcessorPath>
<groupId>org.infinispan.protostream</groupId>
<artifactId>protostream-processor</artifactId>
<version>4.4.1.Final</version>
</annotationProcessorPath>
</annotationProcessorPaths>
</configuration>
</plugin>