5 Replies Latest reply on Oct 17, 2013 10:24 AM by Vikas B

    weblogic 12c resource-ref not working

    Steve Favez Newbie

      I'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 :



      public class TestUserPasswordService {


          @Resource(name = "mydatasource")

          DataSource ressourceRefDs;


          @Resource(name = "jdbc/myDS")

          DataSource directJdniNameDS;




          public static WebArchive createDeployment() {

                JavaArchive ejb = ShrinkWrap.create(JavaArchive.class, "testUserPasswordServices.jar")


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










           * test if datasource has been properly injected.


          public void testDataSourceInjection() {






      What's wrong with my test ? any Idea ?

        • 1. Re: weblogic 12c resource-ref not working
          Vikas B Newbie

          I am getting the same problem.. Does anyone know if this is fixed in 12.1.2. ?

          • 2. Re: weblogic 12c resource-ref not working
            Robert Panzer Newbie



            maybe you cut that out, but your snippet does not show that you are actually adding the test class to the war.

            What kind of container are you using? Embedded, Managed or Remote?


            Additionally I would try

            @Resource(mappedName="mydatasource") (If the test is really executed in the context of the war!)




            AFAIK the name attribute refers to the name that has to be used to address the injection point when configuring the resource-ref using a deployment descriptor.


            Kind regards,


            • 3. Re: weblogic 12c resource-ref not working
              Vikas B Newbie

              I had created sample program and I created datasource using weblogic web console but I am having problem injecting datasource using @Resource..


              here is my sample program :



              package com.xyz.risk.execution.test;


              import javax.inject.Inject;


              import junit.framework.Assert;


              import org.jboss.arquillian.junit.Arquillian;

              import org.junit.Test;

              import org.junit.runner.RunWith;




              public class TestClass extends BasicExecutionTest {



                  private MyTest mytest;



                  public void test() throws Exception {











              package com.xyz.risk.execution.test;


              import org.jboss.arquillian.container.test.api.Deployment;

              import org.jboss.shrinkwrap.api.ShrinkWrap;

              import org.jboss.shrinkwrap.api.spec.WebArchive;


              public class BasicExecutionTest {



                  public static WebArchive createTestArchive() {

                      return ShrinkWrap

                              .create(WebArchive.class, "riskexecution.war")

                              .addPackages(false, "com.xyz.risk.execution.test")



                              .addAsWebInfResource("webapp/WEB-INF/beans.xml", "beans.xml");








              package com.xyz.risk.execution.test;


              import javax.annotation.Resource;

              import javax.ejb.Stateless;

              import javax.sql.DataSource;



              public class MyTest {





                  private DataSource ds;




                  public void testMe() {

                      System.out.println("Testing ... ");



                  public DataSource getDs() {

                      return ds;




                  public void setDs(DataSource ds) {

                      this.ds = ds;








              <?xml version='1.0' encoding='UTF-8'?>

              <jdbc-data-source xmlns="http://xmlns.oracle.com/weblogic/jdbc-data-source" xmlns:sec="http://xmlns.oracle.com/weblogic/security" xmlns:wls="http://xmlns.oracle.com/weblogic/security/wls" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.oracle.com/weblogic/jdbc-data-source http://xmlns.oracle.com/weblogic/jdbc-data-source/1.2/jdbc-data-source.xsd">














                  <test-table-name>SQL SELECT 1 FROM DUAL</test-table-name>







              • 4. Re: weblogic 12c resource-ref not working
                Robert Panzer Newbie



                I don't have WebLogic, but the name property of the annotation does not look right to me.

                @Resource.name is usually not the global JNDI name.


                Did you already try @Resource(lookup="java:/xyz/datasources/xyzRiskDS")? That should refer to a


                Kind regards,


                • 5. Re: weblogic 12c resource-ref not working
                  Vikas B Newbie

                  no, lookup did not work either. Do we have any other alternative ?