java - 在没有数据源的情况下在 Wildfly 中启动 .war

标签 java jakarta-ee jboss wildfly

我遇到了这个荒谬的错误:

jboss.naming.context.java.module.helloworld.helloworld.DefaultDataSource 缺失 [jboss.naming.context.java.jboss.datasources.ExampleDS]

我不明白,因为我的 war 不需要持久性。我真的需要有数据源才能发动 war 吗?

最佳答案

这不是一个错误。 JavaEE 7 强制要求使用 DefaultDataSource。 仅仅因为您没有资源引用并不意味着您不查找它,因此 Wildfly 必须提供映射到 ExampleDS 的 java:comp/DefaultDataSource:

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;

关于java - 在没有数据源的情况下在 Wildfly 中启动 .war,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27596576/

相关文章:

java - 在 NetBeans 平台之外使用 Lookup API

java - 用于在 Android 上比较图像的 OpenGL ES 1.1/2.0 着色器

java - 使用 Tomcat 部署 JAX-RS 应用程序,但始终找不到所需的资源

web-applications - jboss的jmx-console有什么好玩的?

java - 配置 JBoss 以使用 JNDI 的问题 (2)

jboss - 如何将 https-listener 添加到 WildFly 的默认服务器?

java - 在 Java 中将网页响应解析为 Json

java - 服务器端共享 session 是什么场景?

oracle - 我应该使用哪种 JDBC 驱动程序类型来访问 Oracle 数据库?

java - 在Jboss eap 6.1中读取同一个war打包的镜像