我已經搜索了在Wildfly中創建數據源的替代方案,但是我沒有找到替代方法來以編程方式創建它,這可能嗎?如何在Wildfly 10中以編程方式創建數據源?
0
A
回答
1
0
以下示例已使用JBoss-EAP 7.0(使用Wildfly)進行了測試。 Pure Wildfly可能會有不同的maven dependency,提供ModelControllerClient
。這個例子是使用以下Maven依賴關係(從庫https://maven.repository.redhat.com/ga):
<dependency>
<groupId>org.wildfly.core</groupId>
<artifactId>wildfly-controller-client</artifactId>
<version>2.1.13.Final-redhat-1</version>
</dependency>
我假設你已經手動配置數據源和驅動模塊就位jboss/modules/system/layers
,下面的示例使用MySQL
驅動程序。要將驅動程序添加到JBoss配置 ,你必須執行的follwowing代碼:
ModelControllerClient client = ModelControllerClient.Factory.create(InetAddress.getByName("localhost"), 9990);
ModelNode request = new ModelNode();
request.get(ClientConstants.OP).set(ClientConstants.ADD);
request.get(ClientConstants.OP_ADDR).add("subsystem","datasources");
request.get(ClientConstants.OP_ADDR).add("jdbc-driver","mysql");
request.get("driver-name").set("mysql");
request.get("driver-module-name").set("com.mysql");
request.get("driver-xa-datasource-class-name").set("com.mysql.jdbc.jdbc2.optional.MysqlXADataSource");
client.execute(new OperationBuilder(request).build());
client.close();
這將驅動程序添加到您的配置:
<driver name="mysql" module="com.mysql">
<xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
</driver>
添加數據源是不是添加驅動器頗爲相似:
ModelControllerClient client = ModelControllerClient.Factory.create(InetAddress.getByName("localhost"), 9990);
ModelNode request = new ModelNode();
request.get(ClientConstants.OP).set(ClientConstants.ADD);
request.get(ClientConstants.OP_ADDR).add("subsystem","datasources");
request.get(ClientConstants.OP_ADDR).add("data-source","TestDs");
request.get("jta").set(true);
request.get("jndi-name").set("java:jboss/datasources/TestDs");
request.get("pool-name").set("TestDs");
request.get("use-java-context").set(true);
request.get("use-ccm").set(true);
request.get("connection-url").set("jdbc:mysql://localhost/test");
request.get("driver-name").set("mysql");
request.get("transaction-isolation").set("TRANSACTION_READ_COMMITTED");
request.get("min-pool-size").set(5);
request.get("max-pool-size").set(20);
request.get("pool-prefill").set(true);
request.get("pool-use-strict-min").set(false);
request.get("flush-strategy").set("FailingConnectionOnly");
request.get("user-name").set("test");
request.get("password").set("test");
request.get("prepared-statements-cache-size").set(32);
request.get("share-prepared-statements").set(true);
client.execute(new OperationBuilder(request).build());
client.close();
利用該代碼的數據源被編程創建:
<datasource jta="true" jndi-name="java:jboss/datasources/TestDs" pool-name="TestDs" use-java-context="true" use-ccm="true">
<connection-url>jdbc:mysql://localhost/test</connection-url>
<driver>mysql</driver>
<transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>
<pool>
<min-pool-size>5</min-pool-size>
<max-pool-size>20</max-pool-size>
<prefill>true</prefill>
<use-strict-min>false</use-strict-min>
<flush-strategy>FailingConnectionOnly</flush-strategy>
</pool>
<security>
<user-name>test</user-name>
<password>test</password>
</security>
<statement>
<prepared-statement-cache-size>32</prepared-statement-cache-size>
<share-prepared-statements>true</share-prepared-statements>
</statement>
</datasource>
相關問題
- 1. 創建Wildfly 10數據源的問題
- 2. 以編程方式阻止WildFly 10
- 3. 以編程方式在Wildfly/Undertow中創建虛擬主機
- 4. 如何在SQL Server中以編程方式創建數據庫?
- 5. 如何以編程方式在couchdb中創建數據庫?
- 6. 如何以編程方式在c#中創建數據集?
- 7. 以編程方式創建數據庫
- 8. C#以編程方式創建資源
- 9. 以編程方式爲Spring創建JNDI數據源
- 10. 以編程方式創建業務數據內容源
- 11. 如何在環回中以編程方式更改數據源
- 12. 如何以編程方式在ASP.Net中連接LINQ數據源?
- 13. wildfly中的數據源配置10
- 14. 用wildfly 10(activemq)以編程方式刷新消息
- 15. 如何以編程方式創建UIButton
- 16. 如何以編程方式創建GPO?
- 17. 如何以編程方式創建JPEG
- 18. 如何以編程方式創建DrawerLayout
- 19. 如何以編程方式創建NSPopover
- 20. 如何以編程方式創建SplitView?
- 21. 如何以編程方式創建Tabbar
- 22. 如何以編程方式創建UIViewController?
- 23. 如何以編程方式創建UISplitViewController?
- 24. 如何以編程方式創建CustomCell?
- 25. 如何以編程方式創建UIScrollView?
- 26. 如何以編程方式創建dojox.mobile.TabBar?
- 27. 如何以編程方式創建ProgressBar?
- 28. 如何以編程方式創建UIScrollview
- 29. 如何以編程方式創建UICollectionViewCell
- 30. 如何以編程方式創建NSFetchedPropertyDescription?