是否有一种标准方法可以为 Java EE 容器定义 JDBC 数据源? [英] is there a standard way to define a JDBC Datasource for Java EE containers?
问题描述
我知道对于 JBoss,您需要在相应实例的/deploy 子目录中的 [name]-ds.xml 文件.我对其他 Java EE 容器没有任何经验,但我试图尽可能地遵守标准.是否有定义 JDBC 数据源并部署它的标准方法?如果可能,我想将我的数据源包含在 *.ear 文件中(例如,用于演示目的的嵌入式内存 HSQLDB 数据源)?
I know that for JBoss you need a [name]-ds.xml file in the /deploy subdirectory of the appropriate instance. i dont have any experience with other Java EE containers, but im trying to stick to standards as much as possible. is there a standard way to define a JDBC datasource and deploy it ? if possible i'd like to include my datasource inside the *.ear file (for instance, an embedded in-memory HSQLDB datasource for demo purposes) ?
如果没有标准方式,其他容器至少会接受jboss方式吗?(/deploy/*-ds.xml)
if there is no standard way, will other containers at least accept the jboss way ? (/deploy/*-ds.xml)
推荐答案
是否有标准的方法来定义和部署 JDBC 数据源?
Is there a standard way to define a JDBC datasource and deploy it?
是的,有.它是通过
元素完成的,你可以把它放在 web.xml
、ejb-jar.xml
和 中>application.xml
.如果您不喜欢 XML,也可以为此使用注释:@DataSourceDefinition
Yes, there is. It's done via the <data-source>
element, which you can put in web.xml
, ejb-jar.xml
and application.xml
. If you don't like XML, you can also use an annotation for this instead: @DataSourceDefinition
web.xml 条目示例
Example of a web.xml entry
<data-source>
<name>java:app/myDS</name>
<class-name>org.postgresql.xa.PGXADataSource</class-name>
<server-name>pg.myserver.com</server-name>
<database-name>my_db</database-name>
<user>foo</user>
<password>bla</password>
<transactional>true</transactional>
<isolation-level>TRANSACTION_READ_COMMITTED</isolation-level>
<initial-pool-size>2</initial-pool-size>
<max-pool-size>10</max-pool-size>
<min-pool-size>5</min-pool-size>
<max-statements>0</max-statements>
</data-source>
进一步阅读:
ps.我很惊讶所有其他答案都说这不存在,虽然它显然存在,即使在最初提出这个问题的时候也是如此.
这篇关于是否有一种标准方法可以为 Java EE 容器定义 JDBC 数据源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!