2

我试图用 JNoSQL 、 Mongo 和 Wildfly Swarm创建一个你好世界。

@Inject的使用DocumentCollectionManager有效,但不适用于Repository.

这就是我注入的方式:

@Inject
private DocumentCollectionManager entityManager; // works

@Inject
@Database(DatabaseType.DOCUMENT)
private UserRepository userRepository; // do not work! 

这就是我配置生产者的方式:

@ApplicationScoped
public class MongoProducer {
    private static final String DATABASE = "db";

    @Inject
    @ConfigurationUnit(name = "document", fileName = "jnosql.yaml")
    private DocumentCollectionManagerFactory<MongoDBDocumentCollectionManager> entityManager;

    @Produces
    @Database(DatabaseType.DOCUMENT)
    public DocumentCollectionManager getManager() {
        return entityManager.get(DATABASE);
    }

}

如何在 Wildfly Swarm 应用程序中自动注入存储库?

抛出的错误:

2018-05-23 11:30:31,270 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-3) MSC000001: Failed to start service jboss.deployment.unit."demo.war".WeldStartService: org.jboss.msc.service.StartException in service jboss.deployment.unit."demo.war".WeldStartService: Failed to start service
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1978)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type UserRepository with qualifiers @Database
  at injection point [BackedAnnotatedField] @Inject @Database private com.example.demo.rest.HelloWorldEndpoint.userRepository
  at com.example.demo.rest.HelloWorldEndpoint.userRepository(HelloWorldEndpoint.java:0)

    at org.jboss.weld.bootstrap.Validator.validateInjectionPointForDeploymentProblems(Validator.java:362)
    at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:284)
    at org.jboss.weld.bootstrap.Validator.validateGeneralBean(Validator.java:137)
    at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:158)
    at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:501)
    at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:61)
    at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:59)
    at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:62)
    at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:55)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
    at org.jboss.threads.JBossThread.run(JBossThread.java:320)

2018-05-23 11:30:31,278 ERROR [org.jboss.as.controller.management-operation] (main) WFLYCTL0013: Operation ("add") failed - address: (("deployment" => "demo.war")) - failure description: {"WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"demo.war\".WeldStartService" => "Failed to start service
    Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type UserRepository with qualifiers @Database
  at injection point [BackedAnnotatedField] @Inject @Database private com.example.demo.rest.HelloWorldEndpoint.userRepository
  at com.example.demo.rest.HelloWorldEndpoint.userRepository(HelloWorldEndpoint.java:0)
"}}
2018-05-23 11:30:31,279 ERROR [org.jboss.as.server] (main) WFLYSRV0021: Deploy of deployment "demo.war" was rolled back with the following failure message:
{"WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"demo.war\".WeldStartService" => "Failed to start service
    Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type UserRepository with qualifiers @Database
  at injection point [BackedAnnotatedField] @Inject @Database private com.example.demo.rest.HelloWorldEndpoint.userRepository
  at com.example.demo.rest.HelloWorldEndpoint.userRepository(HelloWorldEndpoint.java:0)
"}}
4

1 回答 1

0

怎么样?

您的代码中存在相同的错误:

  • 该接口需要由 CDI 找到,因此我创建了一个 bean.xml 以在您的代码中启用全扫描。在 MongoProducer 你
  • 不需要:@Database(DatabaseType.DOCUMENT)

我创建了一个 PR: https ://github.com/vepo/wildly-swarm-jnosql/pull/1

于 2018-05-24T21:02:29.827 回答