arquillian-glassfish-embedded-3.1 1.0.0.CR3配置JDBC数据源

时间:2012-07-30 20:00:52

标签: jboss-arquillian

我试图使用arquillian-glassfish-embedded-3.1容器来测试和EJB3应用程序。我试图弄清楚如何设置一个简单的JDBC数据源,可以作为资源注入无状态ejb。

这就是我所拥有的:

@Stateless
 public class HelloEJBBean implements HelloEJB {


      @Resource(name="myDataSource")
      private DataSource datasource;




      public String sayHelloEJB(String name) {
                return "Hello " + name;
      }
}

还有arquillian.xml,其中包含以下内容:

<?xml version="1.0"?>
<arquillian xmlns="http://jboss.com/arquillian"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:glassfish="urn:arq:org.jboss.arquillian.container.glassfish.embedded_3">
   <glassfish:container>
      <glassfish:bindHttpPort>9090</glassfish:bindHttpPort>
      <glassfish:instanceRoot>src/test/resources</glassfish:instanceRoot>
      <glassfish:autoDelete>false</glassfish:autoDelete>
   </glassfish:container>
</arquillian>

和带

的domain.xml
<domain>
   <applications />
   <resources>
      <jdbc-resource pool-name="ArquillianEmbeddedOraclePool" jndi-name="myDataSource"
         object-type="user" enabled="true"/>

     <jdbc-connection-pool name="ArquillianEmbeddedOraclePool" res-type="javax.sql.DataSource"
        datasource-classname="oracle.jdbc.driver.OracleDriver">
        <property name="user" value="user"/>
        <property name="password" value="password"/>
        <property name="serverName" value="servername"/>
         <property name="DatabaseName" value="dbname"/>
        <property name="url" value="jdbc:oracle:thin:@servername:1521/dbname"/>
    </jdbc-connection-pool>
   </resources>
</domain>

,简单测试如下:

@RunWith(Arquillian.class)
public class HelloEJBTest {



    @Deployment
    public static JavaArchive createTestArchive() {
        return ShrinkWrap.create(JavaArchive.class, "helloEJB.jar")
                .addClasses(HelloEJB.class, HelloEJBBean.class);
    }

    @EJB
    private HelloEJB helloEJB;


    @Test
    public void testHelloEJB() {
        String result = helloEJB.sayHelloEJB("Michael");
        assertEquals("Hello Michael", result);

    }
}

我收到以下错误:

......还有108个 引起:com.sun.enterprise.container.common.spi.util.InjectionException:尝试注入Res-Ref-Env-Property的异常:myDataSource @javax.sql.DataSource @解析为:jndi:myDataSource @res principal:null @mail:null 没有运行时属性

......还有108个 引起:com.sun.enterprise.container.common.spi.util.InjectionException:尝试注入Res-Ref-Env-Property的异常:myDataSource @javax.sql.DataSource @解析为:jndi:myDataSource @res principal:null @mail:null 没有运行时属性

感谢任何帮助。

由于

0 个答案:

没有答案