我正在尝试在我的EJB模块中创建一个EJB-JPA项目,持久性单元
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="DB">
<jta-data-source>jdbc/db</jta-data-source>
<class>com.demo.entity.TestDept</class>
<class>com.demo.entity.TestEmployee</class>
</persistence-unit>
</persistence>
我在weblogic上测试了数据源,它正在运行。道具就像这样。
@Stateless
public class TestEmployeeDao implements TestEmployeeDaoRemote {
@PersistenceContext(unitName = PersistenceUnits.DB_DATA_SOURCE)
private EntityManager em;
//....
}
我以这种方式注入dao
@EJB
TestEmployeeDaoRemote testEmployeeDao;
我收到此错误
<Sep 5, 2016 5:06:30 PM EEST> <Warning> <Deployer> <BEA-149004> <Failures were detected while initiating deploy task for application "com.Demo-ear_ear_1.0-SNAPSHOT".>
<Sep 5, 2016 5:06:30 PM EEST> <Warning> <Deployer> <BEA-149078> <Stack trace for message 149004
weblogic.management.DeploymentException: java.lang.ClassCastException: weblogic.jndi.internal.WLEventContextImpl cannot be cast to javax.sql.DataSource
at weblogic.application.internal.BaseDeployment.throwAppException(BaseDeployment.java:123)
at weblogic.application.internal.BaseDeployment.prepare(BaseDeployment.java:239)
at weblogic.application.internal.EarDeployment.prepare(EarDeployment.java:61)
at weblogic.application.internal.DeploymentStateChecker.prepare(DeploymentStateChecker.java:158)
at weblogic.deploy.internal.targetserver.AppContainerInvoker.prepare(AppContainerInvoker.java:61)
Truncated. see log file for complete stacktrace
Caused By: java.lang.ClassCastException: weblogic.jndi.internal.WLEventContextImpl cannot be cast to javax.sql.DataSource
at weblogic.persistence.BasePersistenceUnitInfo.lookUpDataSource(BasePersistenceUnitInfo.java:308)
at weblogic.persistence.BasePersistenceUnitInfo.lookUpDataSources(BasePersistenceUnitInfo.java:298)
at weblogic.persistence.BasePersistenceUnitInfo.init(BasePersistenceUnitInfo.java:105)
at weblogic.persistence.BaseJPAIntegrationProvider.createPersistenceUnitInfo(BaseJPAIntegrationProvider.java:53)
at weblogic.persistence.AbstractPersistenceUnitRegistry.storeDescriptors(AbstractPersistenceUnitRegistry.java:420)
Truncated. see log file for complete stacktrace
>
我无法理解这个问题。有帮助吗?