TomEE deploy failed datasource not found

吃可爱长大的小学妹 提交于 2019-12-12 03:22:43

问题


I want to deploy a war file to TomEE but fails with:

Caused by:

javax.naming.NameNotFoundException: 
      Name openejb/Resource/application_name/mysql_ds" not found.

If I restart the server, the deploy goes fine but only once, then the same error encounters.

I have defined datasource in WEB-INF/resources.xml file

<tomee>
    <Resource id="mysql_ds" type="javax.sql.DataSource">
        JdbcDriver  = com.mysql.jdbc.Driver
        JdbcUrl     = jdbc:mysql://IP:3306/db?serverTimezone=UTC&amp;autoReconnect=true
        UserName    = user
        Password    = password
        JtaManaged  = true
    </Resource>
</tomee>

Also i should mention that there is another cloned application(dev mode) with same configuration and it works fine.


回答1:


You can either you use WEB-INF/resources.xml to define one or more datasources or the tomee.xml file inside the <tomee-home>/conf folder, as noted in the corresponding section of the TomEE project documentation:

A DataSource can be declared via xml in the /conf/tomee.xml file or in a WEB-INF/resources.xml file

However, the syntax for resources.xmlis slightly different from the container-wide definition. For a resources.xml bundled with your web-application it should be formulated as follows:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <Resource id="mysql_ds" type="javax.sql.DataSource">
        JdbcDriver  = com.mysql.jdbc.Driver
        JdbcUrl     = jdbc:mysql://IP:3306/db?serverTimezone=UTC&amp;autoReconnect=true
        UserName    = user
        Password    = password
        JtaManaged  = true
    </Resource>
</resources>

Note well, that the tag <resources> is different from <tomee> given in your question. This should work for a default TomEE environment. See also: comment by rmannibucau.

Hope, it helps.



来源:https://stackoverflow.com/questions/38899598/tomee-deploy-failed-datasource-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!