gpt4 book ai didi

java - 在 wildfly-9.0.2.Final 中未找到类型为 'javax.sql.DataSource' 的接口(interface)的 EJB

转载 作者:行者123 更新时间:2023-12-02 03:45:52 28 4
gpt4 key购买 nike

环境 - 应用程序服务器-Wildfly-9.0.2、EJB 3.0在无状态 session 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$000(ComponentInstallProcessor.java:80)
at org.jboss.as.ee.component.deployers.ComponentInstallProcessor$1.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");
}
}
}
}

最佳答案

DataSource 是一种资源,但通常不是 EJB。

只需删除 @EJB 注释,它在这种情况下没有意义。

关于java - 在 wildfly-9.0.2.Final 中未找到类型为 'javax.sql.DataSource' 的接口(interface)的 EJB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36304265/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com