[jboss-user] [JNDI and Naming] - Re: spring 3.x + jboss 7.1.1: how to get the datasource from jndi

Kylin Soong do-not-reply at jboss.com
Thu Jun 20 05:13:17 EDT 2013


Kylin Soong [https://community.jboss.org/people/kylin] created the discussion

"Re: spring 3.x + jboss 7.1.1: how to get the datasource from jndi"

To view the discussion, visit: https://community.jboss.org/message/824041#824041

--------------------------------------------------------------
Do you sure your datasource deploy successful? I have done a test:
1. deploy datasource, the jbdi name like 'java:jboss/datasources/SpringTravelDS', deploy datasource(copy SpringTravel-ds.xml to jboss-eap-6.1/standalone/deployments), datasource content like [1]
2. define jpa persistence.xml file, the persistence.xml should be in app classpath, the content like [2]
3. define spring spring.xml file, the spring.xml should be in app classpath, the content like [3]
After above procedure done, it works pretty fine, I would like post the git url, if I have time to extract a simple one.

[1] SpringTravel-ds.xml
---
<?xml version="1.0" encoding="UTF-8"?>
<datasources xmlns=" http://www.jboss.org/ironjacamar/schema http://www.jboss.org/ironjacamar/schema"
   xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation=" http://www.jboss.org/ironjacamar/schema http://www.jboss.org/ironjacamar/schema  http://docs.jboss.org/ironjacamar/schema/datasources_1_0.xsd http://docs.jboss.org/ironjacamar/schema/datasources_1_0.xsd">
   <!-- The datasource is bound into JNDI at this location. We reference this in META-INF/persistence.xml -->
   <!--H2 -->
   <datasource jndi-name="java:jboss/datasources/SpringTravelDS" pool-name="spring-travel-pool" enabled="true" use-java-context="true">
      <connection-url>jdbc:h2:mem:spring-travel;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1</connection-url>
      <driver>h2</driver>
      <security>
         <user-name>sa</user-name>
         <password>sa</password>
      </security>
   </datasource> 
</datasources>
---

[2] persistence.xml
---
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
   xmlns=" http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence" xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="
         http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence
         http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">

   <persistence-unit name="org.springframework.samples.travel">
      <jta-data-source>java:jboss/datasources/SpringTravelDS</jta-data-source>
      <properties>
           <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
           <property name="hibernate.hbm2ddl.auto" value="create-drop" />
         <property name="hibernate.show_sql" value="true"/>
         <property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider"/>
      </properties>
   </persistence-unit>

</persistence>
---

[3] spring.xml
---
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans"
    xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance http://www.w3.org/2001/XMLSchema-instance"
    xmlns:jdbc=" http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc"    
    xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans  http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
             http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc  http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd">

    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>
    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
        </property>
    </bean>
     <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName">
            <value>java:jboss/datasources/SpringTravelDS</value>
        </property>
    </bean>
</beans>
---
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/824041#824041]

Start a new discussion in JNDI and Naming at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2083]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20130620/0fb9148f/attachment.html 


More information about the jboss-user mailing list