我们制作了许多使用了各种各样的wildflynéejboss迭代的Web应用程序。我们几乎总是使用数据库和JNDI可访问的数据源来进行数据库连接,我们传统上通过deployments文件夹中的xxx-ds.xml文件进行部署。这些自动部署的-ds.xml文件过去很有用,因为我们必须以编程方式进行更改或部署应用程序等。
由于Wildfly 8或9,这种设置数据源的方法已被弃用警告。 wildfly文档几乎专门讨论了使用管理Web界面(一旦项目上线,通常会关闭的东西)。所以使用它对我们来说是不实际或不可取的。考虑到这一点,我们应该如何(通过shell脚本可能通过编程方式)继续设置和配置数据源?
答案 0 :(得分:0)
如果您不想使用Web界面,可以编辑standalone.xml(或您使用的任何版本)文件并添加所需的数据源。
示例:
<subsystem xmlns="urn:jboss:domain:datasources:3.0">
<datasources>
<datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS"
enabled="true" use-java-context="true">
<connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE</connection-url>
<driver>h2</driver>
<security>
<user-name>sa</user-name>
<password>sa</password>
</security>
</datasource>
<datasource jndi-name="java:jboss/datasources/postgresExample" pool-name="postgresExample"
enabled="true" use-java-context="true">
<connection-url>jdbc:postgresql://localhost/postgresExample</connection-url>
<driver>postgres</driver>
<security>
<user-name>postgres</user-name>
<password>postgres</password>
</security>
</datasource>
<drivers>
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>
<driver name="postgres" module="org.postgresql">
<xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
</driver>
</drivers>
</datasources>
</subsystem>
我知道不如部署数据源,也许有人有更好的答案!