Websphere Liberty 18.0.0.3 MySQL 数据源对象未注入



我的 Web 应用程序无法获取在服务器.xml中配置的数据源。 我已经在文件夹下添加了sqlconnector jar(mysql-connector-java-8.0.12(C:wlpusrsharedresourcesmysql

服务器.xml

<!--    Enable    features    -->                
<featureManager>
<feature>cdi-1.2</feature>
<feature>jaxrs-2.0</feature>
<feature>jdbc-4.0</feature>
<feature>jndi-1.0</feature>
<feature>jpa-2.0</feature>
<feature>localConnector-1.0</feature>
<feature>servlet-3.1</feature>
</featureManager>
<!--    Declare    the    jar    files    for    MySQL    access    through    JDBC.    -->
<library id="MySQLLib">
<fileset dir="${shared.resource.dir}/mysql" includes="mysql-connector-java-8.0.12.jar"/>
</library>
<!-- Declare the runtime database -->
<dataSource jndiName="AdminWeb/jdbc/AdminDS" transactional="false">
<jdbcDriver libraryRef="MySQLLib"/>
<properties databaseName="admin" password="****" portNumber="3306" serverName="localhost" user="root"/>
</dataSource>

@Resource(name = "AdminWeb/jdbc/AdminDS",lookup="AdminWeb/jdbc/AdminDS")
DataSource dataSource;
public UserEntity getAllUsers() {
UserEntity user = new UserEntity();
Connection connection = null;
try {
System.out.println("****************1");
connection = dataSource.getConnection();
System.out.println("2");

调用 Web 应用时,getconnection 方法会引发

[错误] SRVE0777E:应用程序类"com.fist.tools.admin.dao.UserDAO.getAllUsers:25"引发的异常 java.lang.NullPointerException

谁能帮我解决这个问题?

数据源/服务器配置本身看起来不错。 @Resource只能注入到 Web 组件/EJB 组件中。 您注入的类是否符合该描述?

最新更新