有没有为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?
是的,有。它是通过< data-source>
元素完成的,您可以将其放入 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>
进一步阅读:
- Introducing the DataSourceDefinition Annotation
- The state of @DataSourceDefinition in Java EE
- Example application use standard data source
ps令我感到惊讶的是,所有其他答案都说这不存在,但很明显,即使在最初询问这个问题时也是如此。
这篇关于有没有为Java EE容器定义JDBC数据源的标准方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!