根据@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});
}
}
具有覆盖方法的上下文初始化器类
import org.infinispan.protostream.SerializationContext;
import java.io.UncheckedIOException;
public class contextInitializer implements DummyInitializer {
@Override
public String getProtoFileName() {
return null;
}
@Override
public String getProtoFile() throws UncheckedIOException {
return null;
}
@Override
public void registerSchema(SerializationContext serCtx) {
}
@Override
public void registerMarshallers(SerializationContext serCtx) {
}
}
然后实例化上下文初始化器的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);
}
}
}
梅文
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-bom</artifactId>
<version>${infinispan.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.infinispan.protostream</groupId>
<artifactId>protostream-processor</artifactId>
<scope>provided</scope>
</dependency>
我仍然没有看到任何自动生成的原始文件。有人能告诉我我做错了什么吗?
您并不是说使用了哪个构建系统。也许是maven?是否将protostream注释处理器添加为依赖项?对这些问题有一个明确的答案将有助于解决代码生成的问题。之后,我们仍然需要找出谁应该初始化dummyInitializer字段。
您还需要添加org。英菲尼斯潘。protostream:protostream处理器
工件作为依赖项,以便生成代码:
<dependency>
<groupId>org.infinispan.protostream</groupId>
<artifactId>protostream-processor</artifactId>
<version>4.3.2.Final</version>
</dependency>
一旦出现,一个DummyInitializerImpl。将生成java类,该类自动注册书籍
和作者
类的原型文件和封送器。记住,为了生成模式和封送器,这些类还必须具有protostream注释。有关代码示例,请参阅文档。
当前代码存在两个问题:
DummyInitializerImpl
类,但这是@AutoProtoSchemaBuilder
应该生成的
DummyInitializerImpl
中,您正在尝试注册书籍
和作者
类型的InfinispanUUIDMarshaller
。这不起作用,因为marshaller是为javaUUID
类设计的
我怀疑这两个问题是由于对代码生成工作原理的错误理解。如果您只需要为作者
和书籍
类使用序列化上下文初始值设定项
,则无需手动创建DummyInitializerImpl
,而且您肯定不需要使用UUIDMarshaller。
当我尝试使用Makefile命令生成proto文件时-,我得到这个错误- 当我运行which go时,我有: 哪个协议返回此- 下面是我的<代码>。zshrc看起来像: 我也安装了插件 请否则我应该添加我的以避免此错误吗?
我有一个golang结构,其中包含对其他结构的引用。有没有一种自动化的方法来生成。结构中的原始文件? 例如: 应生成:
我想序列化Internet上的一个复杂Java对象。第一次,我使用Google Gson来序列化这个类。Gson提供了一种将对象序列化为JSON字符串并通过toJson和fromJson从JSON字符串反序列化到对象的简单方法。然而,JSON字符串并不是很紧凑,在序列化字节[]数组时会带来很大的开销。 我正在阅读Google协议缓冲区。根据教程,用户必须手动为每条消息编写. proto文件。协议缓
我是maven的新手,我正在浏览本教程:Jenkov的maven教程,其中显示“maven archetype:generate”将列出1300多个maven原型。另一个教程也显示了如下结果: $mvn原型:生成 [信息]正在扫描项目。。。[信息][信息]-------------------------------------------------------------[信息]建筑Maven
我正在尝试将一个网站从Heroku迁移到AWS,但在代码构建方面遇到了麻烦。源代码在GitHub上,我使用的是CodePipeline-CodeBuild-Elastic Beanstalk。管道运行良好,代码似乎正在向Elastic Beanstalk过渡。然而,我被困在代码构建步骤。(buildspec.yml如下所示) 日志似乎可以很好地运行命令,但是当我将构建输出到S3存储桶时,没有构建文
"prototype" 属性在 JavaScript 自身的核心部分中被广泛地应用。所有的内置构造函数都用到了它。 首先,我们将看看原生原型的详细信息,然后学习如何使用它为内建对象添加新功能。 Object.prototype 假如我们输出一个空对象: let obj = {}; alert( obj ); // "[object Object]" ? 生成字符串 "[object Object]