在 wildfly-9.0.2.Final 中找不到接口类型为 'javax.sql.DataSource' 的 EJB

No EJB found with interface of type 'javax.sql.DataSource' in wildfly-9.0.2.Final

环境-应用服务器-Wildfly-9.0.2,EJB 3.0 在无状态会话 bean 中,已创建 Jdbc 连接,但部署 jar 失败并出现以下错误,并且在 JBOSS 5.x.

中成功部署了相同的 jar
10:56:08,693 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-1) MSC000001: Failed to start service jboss.deployment.unit."test.jar".INSTALL: org.jboss.msc.service.StartException in service jboss.deployment.unit."test.jar".INSTALL: WFLYSRV0153: Failed to process phase INSTALL of deployment "test.jar"
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:163)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: WFLYEE0052: Failed to install component SlsDetailsBean
at org.jboss.as.ee.component.deployers.ComponentInstallProcessor.deploy(ComponentInstallProcessor.java:109)
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:156)
... 5 more
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: WFLYEJB0406: No EJB found with interface of type 'javax.sql.DataSource' for binding todc.test.ejb.session.SlsDetailsBean/ds2
at org.jboss.as.ejb3.deployment.processors.EjbInjectionSource.getResourceValue(EjbInjectionSource.java:90)
at org.jboss.as.ee.component.deployers.ComponentInstallProcessor.processBindings(ComponentInstallProcessor.java:263)
at org.jboss.as.ee.component.deployers.ComponentInstallProcessor.access[=12=]0(ComponentInstallProcessor.java:80)
at org.jboss.as.ee.component.deployers.ComponentInstallProcessor.handle(ComponentInstallProcessor.java:215)
at org.jboss.as.ee.component.ClassDescriptionTraversal.run(ClassDescriptionTraversal.java:54)
at org.jboss.as.ee.component.deployers.ComponentInstallProcessor.deployComponent(ComponentInstallProcessor.java:211)
at org.jboss.as.ee.component.deployers.ComponentInstallProcessor.deploy(ComponentInstallProcessor.java:101)
... 6 more

JAVA 代码

package todc.test.ejb.session;

import java.io.Serializable;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.annotation.Resource;
import javax.ejb.EJB;
import javax.ejb.Local;
import javax.ejb.Stateless;
import javax.sql.DataSource;
import org.jboss.ejb3.annotation.LocalBinding;

@Local(SlsDetailsLocal.class)
@Stateless
@LocalBinding(jndiBinding="test_SlsDetailsBean/local")
public class SlsDetailsBean implements Serializable, SlsDetailsLocal
{
private static final long serialVersionUID = 1L;
Connection conn=null;
@EJB 
@Resource(mappedName="java:/TESTDS") 
private DataSource ds2;

public void getList() throws Exception
{
    Statement st = null;
    ResultSet rs = null;

    try
    {
        conn = ds2.getConnection();            
        st = conn.createStatement();
    }
    catch(Exception e){
        e.printStackTrace();
    }
    finally{
        try {
            if (rs != null) {
                rs.close();
            }
            if (st != null) {
                st.close();
            }
            if (conn != null) {
                conn.close();
            }
        } catch (Exception ex) {
                ex.printStackTrace();
            System.out.println("[] Error Occured in Closing JDBC Objects");
        }
    }
}
}

A DataSource 是资源,但通常不是 EJB。

只需删除 @EJB 注释,在此上下文中没有意义。