Reputation: 4747
I have this class:
@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
}
}
As you can see, deployment 2 is commented, so my deployment works fine. If I uncomment the @Deployment annotation, utx is not injected anymore and I get a null pointer exception.
Am I missing something? Why adding a new deployment causes my UserTransaction not to be injected anymore?
Upvotes: 1
Views: 599
Reputation: 1892
You have to inject the UserTransaction
as a resource, since it's managed outside the CDI container.
private @Resource UserTransaction transaction;
See this Tutorial.
Upvotes: 2