Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
276 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...