Wednesday, April 14, 2010

jndi configuration in Jboss server

Jijo-ds.xml (put this file in jboss deploy folder)

<datasources>
  <local-tx-datasource>
    <jndi-name>jijoDS</jndi-name>
    <connection-url>jdbc:mysql://localhost:3306/jijo</connection-url>

    <driver-class>com.mysql.jdbc.Driver</driver-class>
    <user-name>root</user-name>
    <password>mysql</password>
    <!-- you can include connection properties that will get passed in

     the DriverManager.getConnection(props) call-->
    <!-- look at your Driver docs to see what these might be -->
    <connection-property name="char.encoding">UTF-8</connection-property>

    <transaction-isolation>TRANSACTION_SERIALIZABLE</transaction-isolation>

    <!--pooling parameters-->
    <min-pool-size>10</min-pool-size>
    <max-pool-size>30</max-pool-size>

    <blocking-timeout-millis>5000</blocking-timeout-millis>
    <idle-timeout-minutes>1</idle-timeout-minutes>
    <!-- sql to call when connection is created -->
    <new-connection-sql>select 1</new-connection-sql>

   

    <!-- sql to call on an existing pooled connection when it is obtained from pool -->
    <check-valid-connection-sql>select 1</check-valid-connection-sql>
   
    <set-tx-query-timeout></set-tx-query-timeout>
    <query-timeout>300</query-timeout> <!-- maximum of 5 minutes for queries -->

  </local-tx-datasource>
</datasources>

in your application WEB-INF/jboss-web.xml
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
        <security-domain>java:/jaas/jmx-console</security-domain> 
         <resource-ref> 
       <res-ref-name>jijoDS</res-ref-name>
       <jndi-name>java:/jijoDS</jndi-name>
   </resource-ref>    
</jboss-web>

in web.xml

<resource-ref>
        <res-ref-name>jijoDS</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>



in applicationContext.xml you are using Spring-Hibernate combination


<bean id="dataSource" class="org.springframework.
jndi.JndiObjectFactoryBean" singleton="true">
     <property name="jndiName">
        <value>java:/jijoDS</value>
     </property>
</bean>

<bean id="hibernateProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean" >
<property name="properties">
<props>
<prop key="hibernate.dialect">dialect name</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.cglib.use_reflection_optimizer">true</prop>
<prop key="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</prop>
<prop key="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</prop>
<prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</prop>
<prop key="hibernate.connection.datasource">java:/comp/env/jdbc/jijoDS</prop>
</props>
</property>
</bean>

No comments: