weblogic 12c resource-ref not working
favez.steve Jan 17, 2013 5:02 AMI'm trying to test the following scenario using weblogic 12c in remote :
An ejb 3.1 jar project, with a simple stateless session bean injecting a datasource using @Resource annotation.
I've a Datasource on my weblogic 12c with a jndi name "jdbc/myDS".
I also have a weblogic-ejb-jar.xml file declaring an ressource ref for my ejb ( name is "mydatasource" ), to create a ressource ref on my global datasource, and the same for a "test" web app (weblogic.xml)
When starting my test with Arquillian, if I use the global jndi name (jdbc/myDS) to inject my datasource, it's working fine. But If I use the resource-ref name ("mydatasource"), datasource can't be found.
Here's the code of my arquillian class :
@RunWith(Arquillian.class)
public class TestUserPasswordService {
@Resource(name = "mydatasource")
DataSource ressourceRefDs;
@Resource(name = "jdbc/myDS")
DataSource directJdniNameDS;
@Deployment
public static WebArchive createDeployment() {
JavaArchive ejb = ShrinkWrap.create(JavaArchive.class, "testUserPasswordServices.jar")
.addClass(UserPasswordService.class).addClass(BusinessException.class)
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
final WebArchive war = ShrinkWrap.create(WebArchive.class, "mytest.war").addAsLibrary(ejb)
.addAsWebInfResource("weblogic.xml").addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
return war;
}
and my weblogic.xml file :
<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-web-app xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.3/weblogic-web-app.xsd">
<wls:resource-description>
<wls:res-ref-name>mydatasource</wls:res-ref-name>
<wls:jndi-name>jdbc/myDS</wls:jndi-name>
</wls:resource-description>
</wls:weblogic-web-app>
@Test
/**
* test if datasource has been properly injected.
*/
public void testDataSourceInjection() {
Assert.assertNotNull(directJdniNameDS);
Assert.assertNotNull(ressourceRefDs);
}
}
What's wrong with my test ? any Idea ?