我想通过声明数据源在 Jboss Wildfly Swarm 中使用postgresql . 应用程序启动错误消息是:
无法为驱动程序org.postgresq加载模块
主类内容:
public static void main(String[] args) throws Exception {
Container container = new Container();
container.fraction(new DatasourcesFraction()
.jdbcDriver("postgresql", (d) -> {
d.driverDatasourceClassName("org.postgresql.Driver");
d.xaDatasourceClass("org.postgresql.xa.PGXADataSource");
d.driverModuleName("org.postgresql");
})
.dataSource("ExampleDS", (ds) -> {
ds.driverName("postgresql");
ds.connectionUrl("jdbc:postgresql://localhost:5432/test_db");
ds.userName("sa");
ds.password("sa");
})
);
container.start();
JAXRSDeployment appDeployment = new JAXRSDeployment( container );
appDeployment.addResource(MyResource.class);
container.deploy(appDeployment);
}
谢谢你的帮助
1 回答
以下wildfly-swarm示例可能很有用 . 它描述了如何在Wildfly Swarm容器中部署驱动程序和数据源:(有IT测试覆盖它)
https://github.com/wildfly-swarm/wildfly-swarm-examples/tree/master/datasource/datasource-deployment
编辑:数据源部署示例文档不是最新的,有效示例here
以下是运行此示例main方法时的日志 . 数据源部署似乎工作正常:
您是否还在类路径中添加了驱动程序库,如果您正在使用maven,则通过在运行时依赖项中声明它?