使用EJB时需要配置数据源,光在代码里面添加配置是不够的,还需要在jboss中配置
首先在jboss-as-web-7.0.2.Final\standalone\configuration目录下standalone.xml中<datasources>
标签中添加你的数据源配置:
这里drivername是mysql
<datasource jndi-name="java:jboss/datasources/localTrans/FirstTest" pool-name="localTrans_FirstTest" enabled="true" jta="true" use-java-context="true" use-ccm="true">
<connection-url>
jdbc:mysql://127.0.0.1:3306/jsftest
</connection-url>
<connection-property name="zeroDateTimeBehavior">
round
</connection-property>
<connection-property name="connectTimeout">
180000
</connection-property>
<connection-property name="socketTimeout">
180000
</connection-property>
<connection-property name="characterEncoding">
UTF-8
</connection-property>
<connection-property name="autoReconnectForPools">
true
</connection-property>
<driver>
mysql
</driver>
<pool>
<min-pool-size>
0
</min-pool-size>
<max-pool-size>
50
</max-pool-size>
<prefill>
false
</prefill>
<use-strict-min>
false
</use-strict-min>
<flush-strategy>
EntirePool
</flush-strategy>
</pool>
<security>
<user-name>
root
</user-name>
<password>
root
</password>
</security>
<validation>
<check-valid-connection-sql>
select 1
</check-valid-connection-sql>
<validate-on-match>
false
</validate-on-match>
<background-validation>
true
</background-validation>
<background-validation-millis>
1800000
</background-validation-millis>
<use-fast-fail>
false
</use-fast-fail>
</validation>
<timeout>
<idle-timeout-minutes>
5
</idle-timeout-minutes>
<query-timeout>
120
</query-timeout>
</timeout>
<statement>
<track-statements>
TRUE
</track-statements>
<prepared-statement-cache-size>
100
</prepared-statement-cache-size>
<share-prepared-statements/>
</statement>
</datasource>
添加<drivers>
下添加driver:
<driver name="mysql" module="com.mysql"/>
然后在modules\com文件夹下建立mysql\main文件夹
main里面添加驱动jar包以及module.xml文件:
path为jar包名,name为上面的module值
这一段可以把modules\com\h2database\h2\main中的module.xml文件复制过来就行修改
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="com.mysql">
<resources>
<resource-root path="mysql-connector-java-5.1.21-bin.jar"/>
<!-- Insert resources here -->
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-10-11 21:27:43