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

Categories

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

is there a standard way to define a JDBC Datasource for Java EE containers?

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) ?

if there is no standard way, will other containers at least accept the jboss way ? (/deploy/*-ds.xml)

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

Is there a standard way to define a JDBC datasource and deploy it?

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

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>

Further reading:

p.s. I'm surprised all other answers say this doesn't exist, while it clearly does, even at the time this question was originally asked.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...