Java 使用vertx embedded和Guice为垂直线设置多个实例

Java 使用vertx embedded和Guice为垂直线设置多个实例,java,guice,inject,vert.x,Java,Guice,Inject,Vert.x,我在同一台机器上使用Vertx群集(开发模式)。 我正在使用guice注入一些pojo 但是,当我尝试增加垂直实例时,我得到: java.lang.IllegalArgumentException: Can't specify > 1 instances for already created verticle at io.vertx.core.impl.DeploymentManager.deployVerticle(DeploymentManager.java:70)

我在同一台机器上使用Vertx群集(开发模式)。 我正在使用guice注入一些pojo

但是,当我尝试增加垂直实例时,我得到:

java.lang.IllegalArgumentException: Can't specify > 1 instances for already created verticle
    at io.vertx.core.impl.DeploymentManager.deployVerticle(DeploymentManager.java:70)
    at io.vertx.core.impl.VertxImpl.deployVerticle(VertxImpl.java:516)
    at io.vertx.core.impl.VertxImpl.deployVerticle(VertxImpl.java:511)
    at com.mycompany.world_map_service.web.starter.StarterVerticle.lambda$main$0(StarterVerticle.java:39)
我是这样配置它的:

 public static void main(String[] args) throws Exception {

        final Logger logger = Logger.getLogger(StarterVerticle.class);


        ClusterManager mgr = new HazelcastClusterManager();
        VertxOptions options = new VertxOptions().setClusterManager(mgr);
        Vertx.clusteredVertx(options, res -> {
            DeploymentOptions deploymentOptions = new DeploymentOptions().setConfig(config);
            if (res.succeeded()) {
                Vertx vertx = res.result();
                //  Injector injector = Guice.createInjector(new AppInjector(vertx));
                Injector injector = Guice.createInjector(new AppInjector(vertx, deploymentOptions));
                vertx.deployVerticle(injector.getInstance(VertxHttpServerVerticle.class), deploymentOptions.setInstances(3));
                ...
}
这是我的AppInjector课程:

public class AppInjector extends AbstractModule {

    private Vertx vertx = null;
    private Context context = null;
    DeploymentOptions deploymentOptions = null;


    public AppInjector(Vertx vertx, DeploymentOptions deploymentOptions) {
        this.vertx = vertx;
        this.context = vertx.getOrCreateContext();
        this.deploymentOptions = deploymentOptions;
    }


    @Override
    protected void configure() {
        bind(LocationService.class).to(LocationServiceImpl.class).in(Singleton.class);
        bind(LocationServiceDAO.class).to(LocationServiceDaoImpl.class).in(Singleton.class);
        bind(RedisRepo.class).toProvider(() -> {
            return new RedisRepo(deploymentOptions.getConfig());
        });
        bind(Neo4jRepo.class).toProvider(() -> {
            return new Neo4jRepo(deploymentOptions.getConfig());
        });
    }
}
知道我为什么会被撞车吗?
我知道我应该按名称使用:
com.mycompany.world\u map\u service.web.http.VertxHttpServerVerticle
,但是如果我注入依赖项,它们将在每个实例中重复,不是吗?

我知道我在这方面有点晚了,但下面是一些可能会发现这个问题的人的“原因”。按照错误消息进行操作:

无法为已创建的垂直体指定>1个实例

您正在使用Guice创建一个Verticle实例,然后尝试部署3个实例,但您已经创建了一个Verticle实例:

vertx.deployVerticle(injector.getInstance(VertxHttpServerVerticle.class), deploymentOptions.setInstances(3));
这就是为什么要传递类名。您可以看到解释上述错误的流程

我知道我应该用名字: “com.mycompany.world\u map\u service.web.http.VertxHttpServerVerticle”但是 如果我注入依赖项,它们将为每个 是吗

我不知道你这是什么意思。如果出于某种原因您不想复制数据/依赖项,那么您可能会涉及到另一个对象、单例或杠杆