我的web应用没有获取在server.xml中配置的数据源。我在文件夹下添加了sqlconnector jar(mysql-connector-java-8.0.12) C:\wlp\usr\shared\resources\mysql
服务器.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");
在调用webapp时,getconnection方法抛出
[错误]srve0777e:应用程序类“com.fist.tools.admin.dao.userdao.ge”引发异常tallusers:25'java.lang.nullpointerexception
谁能帮我一下吗?
1条答案
按热度按时间sg2wtvxw1#
数据源/服务器配置本身看起来不错@资源只能注入到web组件/ejb组件中。你要注入的类符合这个描述吗?