Mittwoch, 9. Februar 2011

Datasources in embedded glassfish container

Ever wondered how you could add a JTA datasource to your embedded glassfish integration tests? You wrote your stateless session bean and now can´t use your persistence.xml and inject your bean, because you don´t have a datasource and connection pool in your app? You should try adding sun-resources.xml with the following content (the following example is for postgres and XA datasources, but you can modify it as you need):


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 Resource Definitions //EN" "http://www.sun.com/software/appserver/dtds/sun-resources_1_3.dtd">
<resources>
<jdbc-resource enabled="true" jndi-name="jdbc/myproductdb" object-type="user" pool-name="myproductTestPool">
</jdbc-resource>
<jdbc-connection-pool allow-non-component-callers="false" associate-with-thread="false" connection-creation-retry-attempts="0" connection-creation-retry-interval-in-seconds="10" connection-leak-reclaim="false" connection-leak-timeout-in-seconds="0" connection-validation-method="auto-commit" datasource-classname="org.postgresql.ds.PGSimpleDataSource" fail-all-connections="false" idle-timeout-in-seconds="300" is-connection-validation-required="false" is-isolation-level-guaranteed="true" lazy-connection-association="false" lazy-connection-enlistment="false" match-connections="false" max-connection-usage-count="0" max-pool-size="32" max-wait-time-in-millis="60000" name="myproductTestPool" non-transactional-connections="false" pool-resize-quantity="2" res-type="javax.sql.DataSource" statement-timeout-in-seconds="-1" steady-pool-size="8" validate-atmost-once-period-in-seconds="0" wrap-jdbc-objects="false">
<property name="User" value="username"/>
<property name="Password" value="password"/>
<property name="DatabaseName" value="dbname"/>
</jdbc-connection-pool>
</resources>

Keine Kommentare:

Kommentar veröffentlichen

Hier kann jeder (auch unregistrierte) Leser seine Meinung kundtun...