首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未注入Websphere 18.0.0.3 MySQL数据源对象

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

Stack Overflow用户
提问于 2018-10-19 16:31:13
回答 1查看 232关注 0票数 1

我的web应用程序没有获得server.xml中配置的数据源。我在C:\wlp\usr\shared\resources\mysql文件夹下添加了sql连接器jar (mysql-连接器-java-8.0.12)

server.xml

代码语言:javascript
复制
<!--    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>

DAO

代码语言:javascript
复制
@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方法抛出

ERROR SRVE0777E:应用程序类SRVE0777E java.lang.NullPointerException引发的异常

有人能帮我一下吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-10-19 16:50:06

dataSource/服务器配置本身看起来很好。@Resource只能注入到web组件/ejb组件中。你要注入的类符合这种描述吗?

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52896515

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档