Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
282 views
in Technique[技术] by (71.8m points)

java - TomEE deploy failed datasource not found

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

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

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...