Caching AutoProtoSchemaBuilder未生成原型文件

Caching AutoProtoSchemaBuilder未生成原型文件,caching,protocol-buffers,infinispan,proto,Caching,Protocol Buffers,Infinispan,Proto,根据@Ryan Emerson的建议更新了我的代码,但我仍然没有看到任何自动生成的Impl文件和proto文件 @AutoProtoSchemaBuilder( includeClasses = { Book.class, Author.class }, schemaFileName = "library.proto", schemaFilePath = "proto/") interface DummyInitializer e

根据@Ryan Emerson的建议更新了我的代码,但我仍然没有看到任何自动生成的Impl文件和proto文件

@AutoProtoSchemaBuilder(
        includeClasses = { Book.class,  Author.class },
        schemaFileName = "library.proto",
        schemaFilePath = "proto/")
        interface DummyInitializer extends SerializationContextInitializer {


}
作者类

public class Author {
    private final String name;
    private final String surname;

    @ProtoFactory
    public Author(String name, String surname) {
        this.name = (String)Objects.requireNonNull(name);
        this.surname = (String)Objects.requireNonNull(surname);
    }

    @ProtoField(
        number = 1
    )
    public String getName() {
        return this.name;
    }

    @ProtoField(
        number = 2
    )
    public String getSurname() {
        return this.surname;
    }

    public boolean equals(Object o) {
        if (this == o) {
            return true;
        } else if (o != null && this.getClass() == o.getClass()) {
            Author author = (Author)o;
            return this.name.equals(author.name) && this.surname.equals(author.surname);
        } else {
            return false;
        }
    }

    public int hashCode() {
        return Objects.hash(new Object[]{this.name, this.surname});
    }
}
图书班

public class Book {
    private final String title;
    private final String description;
    private final int publicationYear;
    private final Set<Author> authors;

    @ProtoFactory
    public Book(String title, String description, int publicationYear, Set<Author> authors) {
        this.title = (String)Objects.requireNonNull(title);
        this.description = (String)Objects.requireNonNull(description);
        this.publicationYear = publicationYear;
        this.authors = (Set)Objects.requireNonNull(authors);
    }

    @ProtoField(
        number = 1
    )
    public String getTitle() {
        return this.title;
    }

    @ProtoField(
        number = 2
    )
    public String getDescription() {
        return this.description;
    }

    @ProtoField(
        number = 3,
        defaultValue = "-1"
    )
    public int getPublicationYear() {
        return this.publicationYear;
    }

    @ProtoField(
        number = 4
    )
    public Set<Author> getAuthors() {
        return this.authors;
    }

    public boolean equals(Object o) {
        if (this == o) {
            return true;
        } else if (o != null && this.getClass() == o.getClass()) {
            Book book = (Book)o;
            return this.publicationYear == book.publicationYear && this.title.equals(book.title) && this.description.equals(book.description) && this.authors.equals(book.authors);
        } else {
            return false;
        }
    }

    public int hashCode() {
        return Objects.hash(new Object[]{this.title, this.description, this.publicationYear, this.authors});
    }
}
然后是实例化上下文初始值设定项的ClassA

public class classA {


  DummyInitializer myInterface= new contextInitializer();



    //Create a new cache instance


    public void startCache() {
        {

          try {
            manager = new DefaultCacheManager("src/main/resources/infinispan.xml");
            GlobalConfigurationBuilder builder= new GlobalConfigurationBuilder();
            builder.serialization().addContextInitializers(myInterface);
            System.out.println("------------------>"+ builder.serialization().addContextInitializers(myInterface));
            cache = manager.getCache();
            System.out.println(cache.getName()+" is initialized ");
          } catch (IOException e) {
            throw new IllegalArgumentException("Failed to initialize cache due to IO error",e);
          }
        }

        }
马文


org.infinispan
英菲尼斯潘物料清单
${infinispan.version}
聚甲醛
进口
org.infinispan.protostream
原始流处理器
假如

我仍然没有看到任何自动生成的原型文件。有人能告诉我我做错了什么吗?

你没有说使用了哪个构建系统。也许是maven?是否将protostream注释处理器添加为依赖项?对这些问题有一个明确的答案将有助于解决代码生成的问题。之后,我们仍然需要找出应该由谁来初始化dummyInitializer字段。

您并不是说使用了哪个构建系统。也许是maven?是否将protostream注释处理器添加为依赖项?对这些问题有一个明确的答案将有助于解决代码生成的问题。之后,我们仍然需要找出谁应该初始化dummyInitializer字段。

您还需要添加
org.infinispan.protostream:protostream processor
工件作为依赖项,以便生成代码:

<dependency>
    <groupId>org.infinispan.protostream</groupId>
    <artifactId>protostream-processor</artifactId>
    <version>4.3.2.Final</version>
</dependency>

org.infinispan.protostream
有关代码示例

当前代码存在两个问题:

  • 您提供了一个
    DummyInitializerImpl
    类,但这是
    @AutoProtoSchemaBuilder
    应该生成的
  • 在您的
    DummyInitializerImpl
    中,您正在尝试注册
    书籍
    作者
    类型的Infinispan
    UUIDMarshaller
    。这不起作用,因为marshaller是为java
    UUID
    类设计的

  • 我怀疑这两个问题是由于对代码生成工作原理的错误理解。如果您只是需要
    作者
    书籍
    类的
    序列化上下文初始值设定项
    ,无需手动创建
    DummyInitializerImpl
    ,也无需使用UUIDMarshaller。

    您还需要添加
    org.infinispan.protostream:protostream processor
    工件作为依赖项,以便生成代码:

    <dependency>
        <groupId>org.infinispan.protostream</groupId>
        <artifactId>protostream-processor</artifactId>
        <version>4.3.2.Final</version>
    </dependency>
    
    
    org.infinispan.protostream
    有关代码示例

    当前代码存在两个问题:

  • 您提供了一个
    DummyInitializerImpl
    类,但这是
    @AutoProtoSchemaBuilder
    应该生成的
  • 在您的
    DummyInitializerImpl
    中,您正在尝试注册
    书籍
    作者
    类型的Infinispan
    UUIDMarshaller
    。这不起作用,因为marshaller是为java
    UUID
    类设计的

  • 我怀疑这两个问题是由于对代码生成工作原理的错误理解。如果您只是需要
    作者
    书籍
    类的
    序列化上下文初始值设定项
    ,没有必要手动创建
    DummyInitializerImpl
    ,您肯定不需要使用UUIDMarshaller。

    我已经根据您的建议更新了我的帖子,但我仍然没有看到上下文初始值设定项创建的proto文件。我使用的是来自ininispan项目的同一Book.class和Author.class文件。您给我的链接也是为了帮助其他人-我有一个相关的问题:如何在没有Maven的情况下执行代码生成?但是通过cmd使用java命令。线路?如果Maven不是您的项目类型,但您仍然希望生成代码…我已经根据您的建议更新了我的帖子,但我仍然没有看到由上下文初始值设定项创建的原型文件。我使用的是来自ininispan项目的同一Book.class和Author.class文件。您给我的链接也是为了帮助其他人-我有一个相关的问题:如何在没有Maven的情况下执行代码生成?但是通过cmd使用java命令。线路?如果Maven不是您的项目类型,但您仍然希望生成代码……我已经根据您提供的建议更新了我的帖子。我已经删除了DummyInitializerImpl,并在classA中直接初始化了DummyInitializer。我仍然没有看到生成DummyInitializerImpl和library.proto。我可以知道我是否正确初始化了classA中的DummyInitializer吗?我是否还需要在包中添加一个空的proto文件夹,以便在编译时添加?我已经试过了,但是我仍然没有看到任何自动生成的东西。我有点困惑,因为我需要以某种方式实例化iterface。假设我创建了一个classB实现DummyInitializer,现在classB将拥有SerializationContextInitializer中实现的所有方法。现在来看看ClassA,我会这样做-DummyInitializer myInterface=new classB();然后在我的startCache方法中,我将执行builder.serialization().addContextInitializers(myInterface);。我仍然没有看到任何原始文件被创建。我想我主要关心的是如何初始化dummyInitializer而不创建另一个具有重写方法的类。比方说,如果我跳过创建dummyInitializerImpl,直接转到classA,那么如何在不创建方法的情况下初始化dummyInitializer?当我在另一个类中初始化它时,它总是创建@override方法。你不应该创建
    contextInitializer
    类。protostream处理器为您生成一个
    DummyInitializerImpl.class
    。然后可以通过
    new DummyInitializerImpl()
    对其进行实例化,以便将其传递给全局配置生成器,例如
    builder.serialization().addContextInitializer
    
    <dependency>
        <groupId>org.infinispan.protostream</groupId>
        <artifactId>protostream-processor</artifactId>
        <version>4.3.2.Final</version>
    </dependency>