问题描述
我想将War文件部署到TomEE,但是失败:
I want to deploy a war file to TomEE but fails with:
原因:
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.
我已经在WEB-INF/resources.xml文件中定义了数据源
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&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.
推荐答案
您可以使用WEB-INF/resources.xml
定义一个或多个数据源,也可以使用<tomee-home>/conf
文件夹中的tomee.xml
文件,如对应部分:
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:
但是,resources.xml
的语法与容器范围的定义稍有不同.对于与您的网络应用程序捆绑在一起的resources.xml
,其格式应如下所示:
However, the syntax for resources.xml
is 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&autoReconnect=true
UserName = user
Password = password
JtaManaged = true
</Resource>
</resources>
请注意,标签<resources>
与问题中给出的<tomee>
不同.这应该适用于默认的TomEE环境.另请参阅:rmannibucau发表的评论.
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.
希望,会有所帮助.
这篇关于找不到TomEE部署失败的数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!