依赖注入在Arquillian测试中不起作用 [英] Dependency injection does not work in Arquillian Test
问题描述
这是测试类:
我尝试注入 Paper
对象,然后执行操作以测试注入是否失败。
This is test class:
I try to inject a Paper
object then perform the action to test whether the injection is failed or not.
@RunWith(Arquillian.class)
public class ExcelProcessorTest {
// Not work. Because Paper and ExcelProcessorTest are in different modules?
@Inject
private Paper paper;
@Deployment
public static JavaArchive createDeployment() {
JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "test.jar")
.addClasses(Paper.class)
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
System.out.println(jar.toString(true));
return jar;
}
@Test
public void notNullTest() {
Assert.assertNotNull(paper); // paper is null here.
}
}
我一直致力于一个项目名为 ftc
,这是 ftc
的结构:
I have been working on a project named ftc
and this is the structure of ftc
:
请注意 ftc
是 ftc - *
的父模块。该项目由Maven大会组织。
Note that ftc
is the parent module of ftc-*
. This project is organized by Maven convention.
ExcelProcessorTest
类位于 ftc-test
模块:
ExcelProcessorTest
class is located in ftc-test
module:
和纸张
类位于 ftc-ejb
模块中:
And Paper
class is located in ftc-ejb
module:
论文
class是一个简单的实体bean:
Paper
class is a simple entity bean:
/**
* Paper generated by hbm2java
*/
@Entity
@Table(name = "paper")
public class Paper implements java.io.Serializable {
private Integer id;
private String title;
private String author;
private String journal;
private String volumn;
private String pages;
private String alternateJournal;
private String issn;
private String doi;
private String acccessionNumber;
private String keywords;
private String abstract_;
private Integer timesCited;
private Integer citedReferenceCount;
private String citedReferenceName;
private String website;
private String pdfPath;
private String issue;
private Integer paperIndexId;
private Integer year; // 论文发表的年份
private String type; // OVERVIEW, EXCEL, PAPER
private SourceFile sourceFile;
private Set<PaperIndex> paperIndexes = new HashSet<PaperIndex>(0);
private Set<Sentence> sentences = new HashSet<Sentence>(0);
public Paper() {
}
有谁可以请告诉我为什么注射失败?
Could anyone please tell me why the injection was failed?
哦..我现在有事要做。我会在几个小时后回到这里。如果您需要任何细节,请发表评论。谢谢。
Oh.. I'v got something to do now. I'll be back here in a few hours. If you need anything detail please comment bellow. Thanks.
推荐答案
我已经弄明白了。
在 Paper
类中,我使用了一些其他类,例如 Sentence.class
, PaperIndex.class
,但我没有在 addClasses()
方法中添加它们。无法找到这个引用的分类,因此注射失败。
I have figured this out.
In Paper
class, I have used some other classes, such as Sentence.class
, PaperIndex.class
, but I did not add them in addClasses()
method. This referred classse can not be found so the injection failed.
我多么愚蠢......
How stupid am I...
这篇关于依赖注入在Arquillian测试中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!