IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Spring Java Discussion :

Spring + JTA + Datasource


Sujet :

Spring Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Inactif  
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    2 189
    Détails du profil
    Informations personnelles :
    Âge : 45
    Localisation : Suisse

    Informations forums :
    Inscription : Mai 2006
    Messages : 2 189
    Par défaut Spring + JTA + Datasource
    Hello,

    Dans la doc de spring il cite notement ceci pour l'utilisation de JTA en mode managé par le container

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
     
    If we use JTA in a J2EE container, as in the 'dataAccessContext-jta.xml'  file from the same sample application, we use a container DataSource, obtained via JNDI, in conjunction with Spring's JtaTransactionManager. The JtaTransactionManager doesn't need to know about the DataSource, or any other specific resources, as it will use the container's global transaction management infrastructure.
     
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:jee="http://www.springframework.org/schema/jee"
    xsi:schemaLocation="
           <a href="http://www.springframework.org/schema/beans" target="_blank">http://www.springframework.org/schema/beans</a> <a href="http://www.springframework.org/schema/beans/spring-beans-2.0.xsd" target="_blank">http://www.springframework.org/schem...-beans-2.0.xsd</a>
           <a href="http://www.springframework.org/schema/jee" target="_blank">http://www.springframework.org/schema/jee</a> http://www.springframework.org/schema/jee/spring-jee-2.0.xsd">
     
      <jee:jndi-lookup id="dataSource" jndi-name="jdbc/jpetstore"/> 
     
      <bean id="txManager" class="org.springframework.transaction.jta.JtaTransactionManager" />
     
      <!-- other <bean/> definitions here -->
     
    </beans>
    cette simple définition nous permet-elle donc de ne rien définir d'autres (sans tx-annotation-driven) et d'utiliser simplement l'annotation @Transactional ?

    EDIT

    Un peu plus loin dans la doc je lis ceci :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
     
    !-- from the file 'context.xml' -->
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:aop="http://www.springframework.org/schema/aop"
           xmlns:tx="http://www.springframework.org/schema/tx"
           xsi:schemaLocation="
           http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
     
      <!-- this is the service object that we want to make transactional -->
      <bean id="fooService" class="x.y.service.DefaultFooService"/>
     
      <!-- enable the configuration of transactional behavior based on annotations -->
      <tx:annotation-driven transaction-manager="txManager"/>
     
      <!-- a PlatformTransactionManager is still required -->
      <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <!-- (this dependency is defined somewhere else) -->
        <property name="dataSource" ref="dataSource"/>
      </bean>
     
      <!-- other <bean/> definitions here -->
     
    </beans>
    Peut on combiner la datasource utilisé ici "dataSource" avec la datasource JNDI utilisé plus haut ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    <jee:jndi-lookup id="dataSource" jndi-name="jdbc/jpetstore"/>

  2. #2
    Membre averti
    Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : Belgique

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29
    Par défaut
    pour notre appli je sais qu on utilise dataSource avec un jndi different en properties donc je suppose que c'est le cas

  3. #3
    Inactif  
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    2 189
    Détails du profil
    Informations personnelles :
    Âge : 45
    Localisation : Suisse

    Informations forums :
    Inscription : Mai 2006
    Messages : 2 189
    Par défaut
    bon je suppose que c'est résolu réponse demain matin ...

  4. #4
    Membre confirmé
    Inscrit en
    Octobre 2007
    Messages
    210
    Détails du profil
    Informations forums :
    Inscription : Octobre 2007
    Messages : 210
    Par défaut
    Je ne comprends pas bien ce que tu demandais.

    Pour utiliser des transactions JTA, tu as besoin de deux choses avec spring :
    - Récupérer la datasource par jndi sur un serveur d'application qui supporte JTA. Autrement dit qui te fournira une datasource supportant les transactions XA (globale). (c'est pas le cas de tomcat).
    => tu l'as fait
    - Ensuite, déclarer un transaction manager JTA. Celui de spring par défaut est capable de trouver tout seul celui qui va bien en fonction du serveur d'application (websphere, jboss, ...). Et bien sur le "bindé" sur ton bean manager (ici via l'annotation-driven).
    => tu l'as fait

  5. #5
    Inactif  
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    2 189
    Détails du profil
    Informations personnelles :
    Âge : 45
    Localisation : Suisse

    Informations forums :
    Inscription : Mai 2006
    Messages : 2 189
    Par défaut
    je ne pouvais pas tester depuis chez moi donc je réfléchissais à voix haute (et j ai toujours pas eu le temps de testé d'ailleurs)

Discussions similaires

  1. Réponses: 8
    Dernier message: 19/01/2011, 11h47
  2. Configuration Hibernate Spring et JTA
    Par totoranky dans le forum Hibernate
    Réponses: 3
    Dernier message: 28/08/2009, 16h03
  3. [Data] Spring + Hibernate + JTA
    Par rico31 dans le forum Spring
    Réponses: 9
    Dernier message: 06/03/2009, 10h51
  4. [Data] [SPRING 2.5][JPA] Configuration JTA pour JPA
    Par Righetto Dominique dans le forum Spring
    Réponses: 0
    Dernier message: 01/08/2008, 14h22
  5. [Data] Problème de connection jdbc avec dataSource Spring
    Par laurent.c123 dans le forum Spring
    Réponses: 3
    Dernier message: 04/03/2008, 12h29

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo