-
1. Re: Injection in JBoss 5.1
aslak Sep 27, 2010 6:08 AM (in response to pnizio)You'll have to lookup in JNDI manually in the current release. As soon as we figure out a good way of mapping between Interface name and JNDI binding for the different servers we'll release it.
@Resource should work.. what is the problem?
-
2. Re: Injection in JBoss 5.1
pnizio Sep 27, 2010 5:17 PM (in response to aslak)I checked out the test you've given and it passes. It's still in green when I change the type of injected resource to UserTransaction. Although when I try it in my own tests I get the NPE
-
3. Re: Injection in JBoss 5.1
aslak Sep 28, 2010 6:25 PM (in response to pnizio)What are you trying to inject?
What's your pom dependencies?
-
4. Re: Injection in JBoss 5.1
pnizio Sep 30, 2010 4:28 AM (in response to aslak)I'm trying to inject UserTransaction into my test:
@Resource
private UserTransaction tx;This works perfectly in my EJBs but not in my test cases. The tx reference is null inside test methods in runtime.
My test dependencies are following:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version><scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-junit</artifactId>
<version>1.0.0.Alpha4</version><scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-jbossas-remote-5.1</artifactId>
<version>1.0.0.Alpha4</version><scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.jbossas</groupId>
<artifactId>jboss-as-client</artifactId>
<version>5.1.0.GA</version>
<type>pom</type><scope>test</scope>
</dependency>
<dependency>
<groupId>org.dbunit</groupId>
<artifactId>dbunit</artifactId>
<version>2.4.8</version><scope>test</scope>
</dependency> -
5. Re: Injection in JBoss 5.1
aslak Sep 30, 2010 8:07 AM (in response to pnizio)Yea, the problem there is that when you don't define a mappedBy="jndi-name", it will try to lookup based on the comp: namespace. So even tho UserTransaction is bound in the EJBs comp: context, the ejbs comp: context is not known outside the EJB.
Based on how the Test Execution call is done currently(http) the request comes in via a Servlet and there for not a part of the same context as the EJB. When we get support for multiple protocols(e.g. EJB remote https://jira.jboss.org/browse/ARQ-223) we can execute within the same context.
So for now you will have to add the global jndi name to the Resource lookup.
-
6. Re: Injection in JBoss 5.1
pnizio Oct 7, 2010 4:44 PM (in response to aslak)Finally I got some time to check your answer. I found out that UserTransaction object is registered in both global and java:comp namespaces. Unfortunately it didn't help much. I tried the following JNDI names of which none was correct: java:comp/UserTransaction, java:/UserTransaction, comp/UserTransaction, java:comp/env/UserTransaction, java:global/comp/UserTransaction, java:global/UserTransaction, java:global:comp/UserTransaction, global:java/comp/UserTransaction, global:java:comp/UserTransaction. And probably a few others I don't remember now. All attempts failed with NPE.
Do you know what is a correct JNDI name for UserTransaction and other resources?
-
7. Re: Injection in JBoss 5.1
jaikiran Oct 8, 2010 2:21 AM (in response to pnizio)1 of 1 people found this helpfulTry:
@Resource(mappedName="UserTransaction") private UserTransaction ut;
-
8. Re: Injection in JBoss 5.1
aslak Oct 8, 2010 5:20 AM (in response to jaikiran)
jaikiran pai wrote:@Resource(mappedName="UserTransaction") private UserTransaction ut;
You beat me to it.. Just tested using "UserTransaction" and it works.
-
9. Re: Injection in JBoss 5.1
pnizio Oct 9, 2010 7:23 PM (in response to aslak)OK, you're right, it works... but only when using IN_CONTAINER run mode. Otherwise it's impossible to get it working.
What a pity I have to stick to the client mode because of the pyramid of dependencies my tests need.