[英]Injecting in Arquillian test class always null
I install JBoss Tools plugin at my Eclipse IDE and create project as New > JBoss Central > Java EE EAR Project . 我在Eclipse IDE上安装了JBoss Tools插件,并将项目创建为New> JBoss Central> Java EE EAR Project 。 I used Wildfly 8.2.0.Final server. 我使用了Wildfly 8.2.0.Final服务器。 EJB module of my project template is as below 我的项目模板的EJB模块如下
Dependencies of Arquillian for my project are created by project template and I didn't modify anythings. Arquillian对我的项目的依赖关系是由项目模板创建的,我没有进行任何修改。 And then I created my first test class as 然后我创建了我的第一个测试类
@RunWith(Arquillian.class)
public class CustomerServiceTest {
@Inject
private CustomerDao customerDao;
@Deployment
public static Archive<?> createDeployment() {
JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "test.jar")
.addAsResource("META-INF/test-persistence.xml","META-INF/persistence.xml")
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
archive.addClass(CustomerDto.class);
archive.addClass(Customer.class);
archive.addClass(CustomerDao.class);
archive.addClass(Dao.class);
System.out.println(archive.toString(true));
return archive;
}
@Test
public void getCustomers() {
// customerDao Always Null
System.out.println("############# Testing Success ##################"+ customerDao);
}
}
Here is console log 这是控制台日志
10:39:19,578 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-7) MSC000001: Failed to start service jboss.deployment.unit."test.war".WeldStartService: org.jboss.msc.service.StartException in service jboss.deployment.unit."test.war".WeldStartService: Failed to start service
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1904) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_40]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_40]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_40]
Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type CustomerDao with qualifiers @Default
at injection point [BackedAnnotatedField] @Inject private com.solt.hms.customer.CustomerServiceTest.customerDao
at com.solt.hms.customer.CustomerServiceTest.customerDao(CustomerServiceTest.java:0)
at org.jboss.weld.bootstrap.Validator.validateInjectionPointForDeploymentProblems(Validator.java:372)
at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:293)
at org.jboss.weld.bootstrap.Validator.validateGeneralBean(Validator.java:134)
at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:167)
at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:531)
at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:68)
at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:66)
at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:60)
at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:53)
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [rt.jar:1.8.0_40]
... 3 more
10:39:19,578 ERROR [org.jboss.as.controller.management-operation] (management-handler-thread - 1) JBAS014613: Operation ("deploy") failed - address: ([("deployment" => "test.war")]) - failure description: {"JBAS014671: Failed services" => {"jboss.deployment.unit.\"test.war\".WeldStartService" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"test.war\".WeldStartService: Failed to start service
Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type CustomerDao with qualifiers @Default
at injection point [BackedAnnotatedField] @Inject private com.solt.hms.customer.CustomerServiceTest.customerDao
at com.solt.hms.customer.CustomerServiceTest.customerDao(CustomerServiceTest.java:0)
"}}
10:39:19,578 ERROR [org.jboss.as.server] (management-handler-thread - 1) JBAS015870: Deploy of deployment "test.war" was rolled back with the following failure message:
{"JBAS014671: Failed services" => {"jboss.deployment.unit.\"test.war\".WeldStartService" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"test.war\".WeldStartService: Failed to start service
Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type CustomerDao with qualifiers @Default
at injection point [BackedAnnotatedField] @Inject private com.mycom.project.customer.CustomerServiceTest.customerDao
at com.mycom.project.customer.CustomerServiceTest.customerDao(CustomerServiceTest.java:0)
"}}
I am totally a newbie in testing with Arquillian. 我是与Arquillian进行测试的新手。 I find and study many examples for Arquillian testing examples. 我发现并研究了许多Arquillian测试示例的示例。 These seems fine but what's wrong with mine ? 这些看起来不错,但是我的问题是什么? Thanks for reading my question . 感谢您阅读我的问题。 Be happy with helping a newbie. 乐于帮助新手。
The error message suggests that JBoss was unable to create an instance of CustomerDao
. 错误消息表明JBoss无法创建CustomerDao
的实例。 The most likely reason for this is one or more missing dependencies. 最可能的原因是一个或多个缺少依赖项。
Perhaps you need to add: 也许您需要添加:
archive.addClass(CustomerDaoImpl.class);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.