1

我有一个从 Maven 管理的 Java 应用程序。我已经使用org.infinispan.client.hotrod.RemoteCacheManager8.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 compilemaven 命令。

目前我正在使用org.apache.maven.plugins,你知道自动生成问题吗?

4

1 回答 1

1

只是为了更新我的帖子。

我发现了这个问题。在 Maven 插件中,注释处理器被禁用。

我添加了protostream-processor的标签,如下所示:

<annotationProcessorPaths>
    <annotationProcessorPath>
       <groupId>org.infinispan.protostream</groupId>
        <artifactId>protostream-processor</artifactId>
        <version>4.4.1.Final</version>
    </annotationProcessorPath>
</annotationProcessorPaths>

<compilerArgument>-proc:none</compilerArgument>不允许注释处理器。 finallymaven-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>
于 2021-12-29T17:07:33.453 回答