According to the JEE spec, there should be a default data source provided to applications using java:comp/DefaultDataSource
. WildFly out of the box will provide that data source as per the spec.
What I can't seem to find is a way of changing the value to point somewhere else without changing the java:comp/DefaultDataSource
mapping on the application itself.
Under "Container" -> "JPA Subsystem" there's a Default DataSource which I have tried setting, but the connection still goes to the
java:jboss/datasources/ExampleDS
@Resource(name = "somedatasource", lookup = "java:comp/DefaultDataSource")
private DataSource ds;
One thing to note, I am not using JPA for the application, I just wanted to get the default data source and use raw JDBC calls as I am working with a lot of LOB data and dynamic table names and it is more only possible on raw JDBC.
The way I test it is
System.out.println(ds.getConnection().getMetaData().getURL());
Which yields jdbc:h2:mem:test
Open your standalone.xml in your favourite editor and locate the line in the urn:jboss:domain:ee:2.0
subsystem that says:
<default-bindings
context-service="java:jboss/ee/concurrency/context/default"
datasource="java:jboss/datasources/ExampleDS"
jms-connection-factory="java:jboss/DefaultJMSConnectionFactory"
managed-executor-service="java:jboss/ee/concurrency/executor/default"
managed-scheduled-executor-service="java:jboss/ee/concurrency/scheduler/default"
managed-thread-factory="java:jboss/ee/concurrency/factory/default"/>
and set the datasource
value to the physical datasource name that you would like to be mapped to java:comp/DefaultDataSource
.