执行构建映像时出现Spring本机错误

w51jfk4q  于 2022-12-13  发布在  Spring
关注(0)|答案(2)|浏览(154)

我正在做一个测试项目,我试图实现AOT与GRPC,它可以通过paketo编译映像,但当运行生成的映像时,它显示错误:“缺少io.grpc.netty.shaded.io.netty.channel.socket.nio.NioSocketChannel.()的本机反射配置。”我尝试通过@TypeHint(types = NioServerSocketChannel.class)引导此类的编译,但没有成功。
项目:https://github.com/thukabjj/spring-boot-grpc/tree/main/simulacao
Print image execution
有人经历过类似的错误吗?

0lvr5msh

0lvr5msh1#

是的,您的提示缺少方法部分......这是我使grpc工作所需的提示(最后一个是针对您描述的错误)

@TypeHints({ //
    @TypeHint(typeNames = "io.grpc.netty.shaded.io.netty.util.internal.shaded.org.jctools.queues.MpscArrayQueueProducerIndexField",
            fields = @FieldHint(name = "producerIndex", allowUnsafeAccess = true)), //
    @TypeHint(typeNames = "io.grpc.netty.shaded.io.netty.util.internal.shaded.org.jctools.queues.MpscArrayQueueProducerLimitField",
            fields = @FieldHint(name = "producerLimit", allowUnsafeAccess = true)), //
    @TypeHint(typeNames = "io.grpc.netty.shaded.io.netty.util.internal.shaded.org.jctools.queues.MpscArrayQueueConsumerIndexField",
            fields = @FieldHint(name = "consumerIndex", allowUnsafeAccess = true)), //
    @TypeHint(typeNames = "io.grpc.netty.shaded.io.netty.util.internal.shaded.org.jctools.queues.BaseMpscLinkedArrayQueueProducerFields",
            fields = @FieldHint(name = "producerIndex", allowUnsafeAccess = true)), //
    @TypeHint(typeNames = "io.grpc.netty.shaded.io.netty.util.internal.shaded.org.jctools.queues.BaseMpscLinkedArrayQueueColdProducerFields",
            fields = @FieldHint(name = "producerLimit", allowUnsafeAccess = true)), //
    @TypeHint(typeNames = "io.grpc.netty.shaded.io.netty.util.internal.shaded.org.jctools.queues.BaseMpscLinkedArrayQueueConsumerFields",
            fields = @FieldHint(name = "consumerIndex", allowUnsafeAccess = true)), //
    @TypeHint(typeNames = "io.grpc.netty.shaded.io.netty.buffer.AbstractByteBufAllocator", access = AccessBits.ALL),
    @TypeHint(typeNames = "io.grpc.netty.shaded.io.netty.channel.ReflectiveChannelFactory", access = AccessBits.ALL),
    @TypeHint(typeNames = "io.grpc.netty.shaded.io.netty.channel.socket.nio.NioSocketChannel", methods = @MethodHint(name = "<init>")) })
iecba09b

iecba09b2#

Sping Boot 3.0和Spring 6.0已经内置了对AOT的支持,所以你不必那么辛苦。你目前需要修补autoconfig元数据并添加一个提示,但是随着时间的推移,我希望这些杂务可以被上游吸收。下面是元数据(src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports):

net.devh.boot.grpc.server.autoconfigure.GrpcAdviceAutoConfiguration
net.devh.boot.grpc.server.autoconfigure.GrpcHealthServiceAutoConfiguration
net.devh.boot.grpc.server.autoconfigure.GrpcMetadataConsulConfiguration
net.devh.boot.grpc.server.autoconfigure.GrpcMetadataEurekaConfiguration
net.devh.boot.grpc.server.autoconfigure.GrpcMetadataNacosConfiguration
net.devh.boot.grpc.server.autoconfigure.GrpcMetadataZookeeperConfiguration
net.devh.boot.grpc.server.autoconfigure.GrpcReflectionServiceAutoConfiguration
net.devh.boot.grpc.server.autoconfigure.GrpcServerAutoConfiguration
net.devh.boot.grpc.server.autoconfigure.GrpcServerFactoryAutoConfiguration
net.devh.boot.grpc.server.autoconfigure.GrpcServerMetricAutoConfiguration
net.devh.boot.grpc.server.autoconfigure.GrpcServerSecurityAutoConfiguration
net.devh.boot.grpc.server.autoconfigure.GrpcServerTraceAutoConfiguration

下面是包含提示的应用程序:

@SpringBootApplication
@ImportRuntimeHints(DemoApplicationRuntimeHints.class)
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

}

class DemoApplicationRuntimeHints implements RuntimeHintsRegistrar {

    @Override
    public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
        hints.reflection().registerType(AbstractByteBufAllocator.class, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.INVOKE_DECLARED_METHODS);
    }

}

有一个完整的示例here

相关问题