我试图用 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)
"}}