我有一个非常简单的 Web 应用程序在WebSphere Application Server 18.0.0.2
. 该应用程序被打包到 WAR 中并放在下面dropins
(为简单起见)。
我的server.xml
样子是这样的:
<?xml version="1.0" encoding="UTF-8"?>
<server description="new server">
<featureManager>
<feature>javaee-8.0</feature>
</featureManager>
<httpEndpoint id="defaultHttpEndpoint" httpPort="9080" httpsPort="9443" />
<!-- Automatically expand WAR files and EAR files -->
<applicationManager autoExpand="true"/>
<!-- THE JAR IS THERE (UNDER Liberty lib directory) -->
<library id="H2JDBCLib">
<fileset dir="${wlp.install.dir}/lib" includes="h2-1.4.197.jar"/>
</library>
<!-- AND THIS IS MY DATA SOURCE DEFINITION -->
<dataSource id="h2test" jndiName="jdbc/h2test">
<jdbcDriver libraryRef="H2JDBCLib"/>
<properties.db2.jcc databaseName="testdb" serverName="localhost" portNumber="8082" user="sa" />
</dataSource>
</server>
我有一个非常简单的实体和服务(无状态 EJB):
@Stateless
public class CustomerService {
@PersistenceContext(unitName = "h2test")
private EntityManager entityManager;
public List<Customer> getAllCustomers() {
return entityManager
.createNamedQuery(FIND_ALL, Customer.class)
.getResultList();
}
}
而我persistence.xml
在 META-INF 下的样子是这样的:
<?xml version="1.0" encoding="UTF-8"?>
<persistence 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_1_0.xsd"
version="1.0">
<persistence-unit name="h2test" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>jdbc/h2test</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
</persistence-unit>
</persistence>
我认为这些简单的配置应该足以部署和运行这个 hello-world 类型的应用程序。但我在运行时遇到错误:
[ERROR ] CNTR0019E: EJB throws an exception when invoking "getAllCustomers".
Details: javax.ejb.EJBException: The java:comp/env/com.my.app.service.CustomerService/entityManager reference of type javax.persistence.EntityManager for the null component in the my-app.war module of the my-app application cannot be resolved.
at com.ibm.wsspi.injectionengine.InjectionBinding.getInjectionObject(InjectionBinding.java:1489)
at [internal classes]
at com.my.app.service.EJSLocalNSLCustomerService_22d8d9f5.getAllCustomers(EJSLocalNSLCustomerService_22d8d9f5.java)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
EntityManager 注入失败。从 IBM 的文档中还不清楚还应该做什么。
我的应用程序中没有其他 XML 文件(配置文件)。
我错过了什么吗?