Pergunta

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.
    }

}

I have been working on a project named ftc and this is the structure of ftc:
enter image description here

Note that ftc is the parent module of ftc-*. This project is organized by Maven convention.

ExcelProcessorTest class is located in ftc-test module: enter image description here

And Paper class is located in ftc-ejb module:
enter image description here

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.

Foi útil?

Solução

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...

Outras dicas

I was stumbling upon the same thing, for me using @EJB instead of @Inject worked out perfectly... just to provide a hint but no explanation why.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top