gpt4 book ai didi

mysql - 尝试使用 @DataSourceDefinition 部署数据源时出现 ClassNotFoundException

转载 作者:行者123 更新时间:2023-11-29 23:19:54 24 4
gpt4 key购买 nike

我正在尝试使用 @DataSourceDefinition-Annotation 部署数据源。

当 Wildfly 部署 jar 时,它会抛出 ClassNotFoundException。

我将 mysql-jdbc-Driver 放在部署目录中。我已经在standalone.xml中配置的数据源中使用了com.mysql.jdbc.Driver类。我还没有在“modules\system\layers\base”下使用 jdbc-driver 创建模块

这是带有注释的类:

@Stateless
@DataSourceDefinition(name = "java:global/jdbc/testingDS",
className = "com.mysql.jdbc.Driver",
portNumber = 3306,
serverName = "localhost",
databaseName = "testing",
user = "testing",
password = "testing")

public class DataSourceDeployment {
public void someMethod() { }
}

这是异常(这是 *.failed-File):

{
"JBAS014671: Failed services" => {"jboss.deployment.unit.\"DatasourceDeploymentTest-1.jar\".INSTALL" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"DatasourceDeploymentTest-1.jar\".INSTALL: JBAS018733: Failed to process phase INSTALL of deployment \"DatasourceDeploymentTest-1.jar\"
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver from [Module \"deployment.DatasourceDeploymentTest-1.jar:main\" from Service Module Loader]
Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver from [Module \"deployment.DatasourceDeploymentTest-1.jar:main\" from Service Module Loader]"},
"JBAS014771: Services with missing/unavailable dependencies" => [
"jboss.naming.context.java.comp.DatasourceDeploymentTest-1.DatasourceDeploymentTest-1.DataSourceDeployment.InstanceName is missing [jboss.naming.context.java.comp.DatasourceDeploymentTest-1.DatasourceDeploymentTest-1.DataSourceDeployment]",
"jboss.naming.context.java.comp.DatasourceDeploymentTest-1.DatasourceDeploymentTest-1.DataSourceDeployment.ORB is missing [jboss.naming.context.java.comp.DatasourceDeploymentTest-1.DatasourceDeploymentTest-1.DataSourceDeployment]",
"jboss.deployment.unit.\"DatasourceDeploymentTest-1.jar\".weld.weldClassIntrospector is missing [jboss.deployment.unit.\"DatasourceDeploymentTest-1.jar\".beanmanager]",
"jboss.naming.context.java.comp.DatasourceDeploymentTest-1.DatasourceDeploymentTest-1.DataSourceDeployment.HandleDelegate is missing [jboss.naming.context.java.comp.DatasourceDeploymentTest-1.DatasourceDeploymentTest-1.DataSourceDeployment]",
"jboss.naming.context.java.comp.DatasourceDeploymentTest-1.DatasourceDeploymentTest-1.DataSourceDeployment.ValidatorFactory is missing [jboss.naming.context.java.comp.DatasourceDeploymentTest-1.DatasourceDeploymentTest-1.DataSourceDeployment]",
"jboss.naming.context.java.comp.DatasourceDeploymentTest-1.DatasourceDeploymentTest-1.DataSourceDeployment.InAppClientContainer is missing [jboss.naming.context.java.comp.DatasourceDeploymentTest-1.DatasourceDeploymentTest-1.DataSourceDeployment]",
"jboss.naming.context.java.comp.DatasourceDeploymentTest-1.DatasourceDeploymentTest-1.DataSourceDeployment.Validator is missing [jboss.naming.context.java.comp.DatasourceDeploymentTest-1.DatasourceDeploymentTest-1.DataSourceDeployment]"
]
}

最佳答案

CFNE 就该如此。

您的模块中有 mysql jdbc 驱动程序,但您的部署及其 @DataSourceDefinition 知道它。

@DataSourceDefinition 使用部署类加载器来加载 jdbc 驱动程序,但它在模块中不可用。

要解决这个问题,您应该

1) 通过manifest.mf/jboss-deployment-struct.xml 添加部署对mysql驱动模块的依赖,参见https://docs.jboss.org/author/display/WFLY8/Class+Loading+in+WildFly详细信息如何

2) 将jdbc驱动添加到war的lib目录

但我肯定会选择 1)

关于mysql - 尝试使用 @DataSourceDefinition 部署数据源时出现 ClassNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27417150/

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