gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 05:08:03 27 4
gpt4 key购买 nike

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

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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com