我有一个从 Maven 管理的 Java 应用程序。我已经使用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
,你知道自动生成问题吗?