Arquilian无法为多个部署注入UserTransaction

时间:2015-11-27 10:19:48

标签: java java-ee jboss-arquillian

我有这堂课:

@RunWith(Arquillian.class)
public class myIT {
    @Inject
    private UserTransaction utx;

    @Resource(mappedName="java:/jdbc/myDS")
    private DataSource dataSource;

    @Deployment(name="DeployOne", order = 1)
    public static Archive<?> deployOne() throws FileNotFoundException {
        //Build and return the file
    }

    // @Deployment(name="DeployTwo", order = 2)
    public static Archive<?> deployTwo() throws FileNotFoundException {
        //Build an empty file return the file
        return = ShrinkWrap.create(WebArchive.class, "deployTwo.war");
    }

    @Before
    public void setup() throws Exception {
        utx.begin();
        //Do things with utx
    }
}

如您所见,部署2已被注释,因此我的部署工作正常。 如果我取消注释@Deployment注释,则不再注入utx并且我得到空指针异常。

我错过了什么吗?为什么添加新部署会导致我的UserTransaction不再被注入?

1 个答案:

答案 0 :(得分:1)

您必须将UserTransaction作为资源注入,因为它是在CDI容器外部管理的。

private @Resource UserTransaction transaction;

请参阅此Tutorial