1. 程式人生 > >spring 遠端jndi連線池

spring 遠端jndi連線池

1. JBOSS 下如何配置C3P0的連線池

1.cp30.jar放入server\default\lib中

2.修改xxx-ds.xml

註釋 <!--<local-tx-datasource> </local-tx-datasource>-->

3.建立xxx-service.xml(以sqlserver為例)

<mbean code="com.mchange.v2.c3p0.jboss.C3P0PooledDataSource" name="jboss:service=xxxPolledDataSource"> <attribute name="JndiName">java:xxxds</attribute> <attribute name="JdbcUrl">jdbc:sqlserver://localhost:1433;DatabaseName=test;SelectMethod=cursor</attribute> <attribute name="DriverClass">com.microsoft.sqlserver.jdbc.SQLServerDriver</attribute> <attribute name="User">sa</attribute> <attribute name="Password">sa</attribute> <depends>jboss:service=Naming</depends> </mbean>

2. spring 遠端呼叫jndi 連線池

<beanid="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"> <propertyname="jndiName"value="C3P0Pool"/> <propertyname="jndiTemplate"ref="jndiTemplate"></property> </bean>

<beanid="jndiTemplate" class="org.springframework.jndi.JndiTemplate"

> <propertyname="environment"> <props> <propkey="java.naming.factory.initial"> org.jnp.interfaces.NamingContextFactory </prop> <propkey="java.naming.provider.url"> jnp://127.0.0.1:1099 </prop> <propkey="java.naming.factory.url.pkgs"> org.jboss.naming:org.jnp.interfaces
</prop> <propkey="jnp.disableDiscovery">true</prop> </props> </property> </bean>

異常:Cannot convert value of type [javax.naming.Reference] to required type [javax.sql.DataSource] for property 'dataSource'
上面這個異常是由於沒有對應的jar包造成的,我也是找了很久才找到的。把下面的jar從jboss中取出放到專案中就OK了。
- client/jnp-client.jar
- client/jboss-logging.jar
- common/lib/jbosscx-client.jar