Dr.Knowitall
Dr.Knowitall

Reputation: 10508

Launch .war in wildfly with no Datasource

I'm getting this ridiculous error:

jboss.naming.context.java.module.helloworld.helloworld.DefaultDataSource is missing [jboss.naming.context.java.jboss.datasources.ExampleDS]

Which I don't get since my war doesn't use persistence. Do I really need to have a datasource to launch a war?

Upvotes: 0

Views: 273

Answers (1)

Robert Panzer
Robert Panzer

Reputation: 1519

That's not an error. JavaEE 7 mandates a DefaultDataSource. Just because you don't have a resource-ref to it doesn't mean that you don't look it up, so Wildfly has to provide java:comp/DefaultDataSource which maps to the ExampleDS:

EE.5.19 Default Data Source
The Java EE Platform requires that a Java EE Product Provider provide a database
in the operational environment (see Section EE.2.6, “Database”). The Java EE
Product Provider must also provide a preconfigured, default data source for use by
the application in accessing this database.

The Java EE Product Provider must make the default data source accessible to
the application under the JNDI name java:comp/DefaultDataSource.

The Application Component Provider or Deployer may explicitly bind a
DataSource resource reference to the default data source using the lookup element
of the Resource annotation or the lookup-name element of the resource-ref
deployment descriptor element. For example,

@Resource(lookup="java:comp/DefaultDataSource")
DataSource myDS;

In the absence of such a binding, the mapping of the reference will default to
the product's default data source.

For example, the following will map to a preconfigured data source for the
product's default database:

@Resource
DataSource myDS;

Upvotes: 2

Related Questions