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 3.3. Configuration [Framework]


Sujet :

Spring Java

  1. #21
    Membre chevronné
    Homme Profil pro
    Ed Nat
    Inscrit en
    Janvier 2013
    Messages
    325
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Calvados (Basse Normandie)

    Informations professionnelles :
    Activité : Ed Nat
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Janvier 2013
    Messages : 325
    Par défaut
    donc dans la classe on devrait avoir :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    @Value("${my.propertie}")
    private String myPropertie;
    plutôt que ${my.Key}
    non ?

  2. #22
    Membre très actif
    Avatar de Khaled.Noordin
    Homme Profil pro
    Inscrit en
    Janvier 2005
    Messages
    354
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Janvier 2005
    Messages : 354
    Billets dans le blog
    1
    Par défaut

    désolé de jouer les trouble-fêtes mais la version 3.3 existe pas à ce jour

  3. #23
    Membre émérite Avatar de noOneIsInnocent
    Homme Profil pro
    Inscrit en
    Mai 2002
    Messages
    1 037
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mai 2002
    Messages : 1 037
    Par défaut
    Désolé pour la version je me suis trompé, c'est la 3.1
    ok je vais tester avec la clé mais demain ....
    merci encore
    je vous tiens au courant



  4. #24
    Membre émérite Avatar de noOneIsInnocent
    Homme Profil pro
    Inscrit en
    Mai 2002
    Messages
    1 037
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mai 2002
    Messages : 1 037
    Par défaut
    juste une remarque
    je viens de trouver le lien suivant:

    http://forum.springsource.org/showth...lderconfigurer

    est-ce que quelqu'un peut me confirmer que le problème vient de la présence d'un point dans la clé de propriété ?

  5. #25
    Membre très actif
    Avatar de Khaled.Noordin
    Homme Profil pro
    Inscrit en
    Janvier 2005
    Messages
    354
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Janvier 2005
    Messages : 354
    Billets dans le blog
    1
    Par défaut
    question bête peut être, mais tu as mis un setter sur ton champ annoté @Value?

  6. #26
    Membre émérite Avatar de noOneIsInnocent
    Homme Profil pro
    Inscrit en
    Mai 2002
    Messages
    1 037
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mai 2002
    Messages : 1 037
    Par défaut
    je pensais que le @Value devait se mettre uniquement sur le membre de la classe ?
    du coup c'est quoi la bonne façon ?

  7. #27
    Membre émérite Avatar de noOneIsInnocent
    Homme Profil pro
    Inscrit en
    Mai 2002
    Messages
    1 037
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mai 2002
    Messages : 1 037
    Par défaut
    pour faire avancer le bouzin voici la log qui répond au problème
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    Le Nom my.property n'est pas lié ce Contexte. Returning null.
    reste à trouvé comment mettre mon bean dans le contexte
    si vous avez une idée

  8. #28
    Membre chevronné
    Homme Profil pro
    Ed Nat
    Inscrit en
    Janvier 2013
    Messages
    325
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Calvados (Basse Normandie)

    Informations professionnelles :
    Activité : Ed Nat
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Janvier 2013
    Messages : 325
    Par défaut
    Bonjour,
    non, le @Value("${valueKey}") se met bien sur la déclaration du membre.
    Les accesseurs jouent ensuite juste leur rôle.

    Par contre as tu essayé sans le dot, avec myProperty par exemple, et en modifiant également la clé dans le fichier file.properties ?

    ou avec l'annotation @Value("${my['property']}") si la clé est toujours my.property

    Et tu peux aussi essayer la déclaration plus classique des locations de bean dans applicationContext.xml comme le suggérait HadanMarv :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
           <list>
             <value>classpath:file.properties</value>
          </list>
        </property>
    </bean>

  9. #29
    Membre émérite Avatar de noOneIsInnocent
    Homme Profil pro
    Inscrit en
    Mai 2002
    Messages
    1 037
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mai 2002
    Messages : 1 037
    Par défaut
    j'ai essayé en mettant

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     
    <bean name="propertyPlaceholder"
            class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
            <property name="locations">
                <list>
                    <value>classpath:myFile.properties</value>
                </list>
            </property>
            <property name="localOverride"  value="true"/>
        </bean>
    et j'ai une belle erreur au démarrage de mon appli

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    java.io.FileNotFoundException: class path resource  [myFile.properties] cannot be opened because it does not exist
    je précise qu'en faisant un

    j'ai bien le répertoire où est situé le fichier de configuration

  10. #30
    Membre émérite Avatar de noOneIsInnocent
    Homme Profil pro
    Inscrit en
    Mai 2002
    Messages
    1 037
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mai 2002
    Messages : 1 037
    Par défaut
    mais en mettant ma configuration initiale je vois biens que dans les logs il trouve ma propriété mais que visiblement elle n'est pas dans le même contexte que mon bean
    et je pense que c'est ça qui pose problème
    et je ne sais pas comment les mettre dans le même contexte

  11. #31
    Membre chevronné
    Homme Profil pro
    Ed Nat
    Inscrit en
    Janvier 2013
    Messages
    325
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Calvados (Basse Normandie)

    Informations professionnelles :
    Activité : Ed Nat
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Janvier 2013
    Messages : 325
    Par défaut
    ok
    Peux-tu donner ces infos :

    • Le fichier applicationContext.xml
    • Le contenu du fichier properties et l'endroit où il se trouve
    • Le contenu du Bean

  12. #32
    Membre émérite Avatar de noOneIsInnocent
    Homme Profil pro
    Inscrit en
    Mai 2002
    Messages
    1 037
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mai 2002
    Messages : 1 037
    Par défaut
    Voici les fichiers

    applicationContext.xml qui se trouve dans le WEB-INF
    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
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
     
    <?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:context="http://www.springframework.org/schema/context"
        xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util"
        xmlns:ftp="http://www.springframework.org/schema/integration/ftp"
        xmlns:si="http://www.springframework.org/schema/integration"
        xmlns:batch="http://www.springframework.org/schema/batch"
        xmlns:task="http://www.springframework.org/schema/task"
        xmlns:jaxws="http://cxf.apache.org/jaxws"
        xsi:schemaLocation="
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
            http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd
            http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd 
            http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
            http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.1.xsd
            http://www.springframework.org/schema/integration/ftp http://www.springframework.org/schema/integration/ftp/spring-integration-ftp-2.1.xsd
            http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
     
        <context:annotation-config />
        <context:component-scan base-package="com.package" />
     
        <bean name="propertyPlaceholder" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
                <property name="locations">
                    <list>
                        <value>file:///${DIRECTORY_CONFIGURATION}/my.properties</value>
                    </list>
                </property>
                <property name="localOverride"  value="true"/>
        </bean>
     
        <import resource="classpath:META-INF/cxf/cxf.xml" />
        <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
        <import resource="classpath:ftp-context.xml" />
     
        <bean id="myClasse" class="com.package.MyClasse"  name="MyClasse">
         </bean>
     
        <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
            <property name="sessionFactory" ref="sessionFactory" />
        </bean>
     
        <bean id="sqlServerDataSource"
            class="org.springframework.jdbc.datasource.DriverManagerDataSource">
            <property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
            <property name="url"
                value="${conf.db.url}"/>
            <property name="username" value="${conf.db.username}" />
            <property name="password" value="${conf.db.password}" />
        </bean>    
     
    </beans>
    La fichier my.properties qui se trouve dans le répertoire DIRECTORY_CONFIGURATION:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    conf.dateformat = MM/dd/yy
    Mon bean
    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
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
     
    package com.package.model;
     
     
     
    public class MyClasse {
     
        private Logger logger = LoggerFactory
                .getLogger(MyClasse.class);
        @Value("${conf.dateformat}")
        private String dateFormat;
     
        public String getDateFormat() {
            return dateFormat;
        }
     
        public void setDateFormat(String _dateFormat) {
            this.dateFormat = _dateFormat;
        }
     
        public MyClasse() {
     
        }
     
        public void getObject() {
            getTask();
        }
     
     
        private Object getTask(Map<String, Object> _map) {
            Object ob = new Object();
            logger.debug("date format:" + dateFormat);
            return ob;
     
        }
     
     
    }
    et dans mon logger de la méthode getTask j'ai un beau "date format:null"


    Au passage les propriétés ci-dessous sont bien settées
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    <property name="url"             value="${conf.db.url}"/>         <property name="username" value="${conf.db.username}" />         <property name="password" value="${conf.db.password}" />
    Je ne peux pas mettre le code exactes vu que c'est des classes clientes

  13. #33
    Membre chevronné
    Homme Profil pro
    Ed Nat
    Inscrit en
    Janvier 2013
    Messages
    325
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Calvados (Basse Normandie)

    Informations professionnelles :
    Activité : Ed Nat
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Janvier 2013
    Messages : 325
    Par défaut
    C'est peut-être en me recopiant les fichiers que tu t'es trompé, mais il y a une non correspondance de package entre le bean déclaré dans applicationContext.xml

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    <bean id="myClasse" class="com.package.MyClasse"  name="MyClasse">
         </bean>
    et la classe du Bean :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    package com.package.model;
    mais je suppose que si c'était ça Spring t'enverrai un message d'erreur qqpart...

  14. #34
    Membre émérite Avatar de noOneIsInnocent
    Homme Profil pro
    Inscrit en
    Mai 2002
    Messages
    1 037
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mai 2002
    Messages : 1 037
    Par défaut
    sorry ..c'est une mauvaise recopie
    c'est bien :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    <bean id="myClasse" class="com.package.model.MyClasse"  name="MyClasse">      </bean>

  15. #35
    Membre chevronné
    Homme Profil pro
    Ed Nat
    Inscrit en
    Janvier 2013
    Messages
    325
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Calvados (Basse Normandie)

    Informations professionnelles :
    Activité : Ed Nat
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Janvier 2013
    Messages : 325
    Par défaut
    Tout comme tu as l'annotation @Component sur ta classe, je suppose...

    Et sinon, as-tu essayé sans le dot, avec dans le properties file :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    dateformat = MM/dd/yy
    et dans la classe :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    @Value("${dateformat}")
        private String dateFormat;

  16. #36
    Membre émérite Avatar de noOneIsInnocent
    Homme Profil pro
    Inscrit en
    Mai 2002
    Messages
    1 037
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mai 2002
    Messages : 1 037
    Par défaut
    j'ai le component bien sûr
    mais je n'ai pas essayé sans le dot
    je fais le test et je te redis

  17. #37
    Membre émérite Avatar de noOneIsInnocent
    Homme Profil pro
    Inscrit en
    Mai 2002
    Messages
    1 037
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mai 2002
    Messages : 1 037
    Par défaut
    pas mieux

  18. #38
    Membre chevronné
    Homme Profil pro
    Ed Nat
    Inscrit en
    Janvier 2013
    Messages
    325
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Calvados (Basse Normandie)

    Informations professionnelles :
    Activité : Ed Nat
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Janvier 2013
    Messages : 325
    Par défaut
    Tout comme tu as bien :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    <context:component-scan base-package="com.package.model" />
    ?

  19. #39
    Membre émérite Avatar de noOneIsInnocent
    Homme Profil pro
    Inscrit en
    Mai 2002
    Messages
    1 037
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mai 2002
    Messages : 1 037
    Par défaut
    non j'ai juste
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    <context:component-scan base-package="com.package" />
    mais même en mettant
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    <context:component-scan base-package="com.package.model" />
    ça ne change rien

  20. #40
    Membre chevronné
    Homme Profil pro
    Ed Nat
    Inscrit en
    Janvier 2013
    Messages
    325
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Calvados (Basse Normandie)

    Informations professionnelles :
    Activité : Ed Nat
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Janvier 2013
    Messages : 325
    Par défaut
    Et comment se fait le chargement du contexte ?
    via la servlet :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    <servlet>
      <servlet-name>context</servlet-name>
      <servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
      <load-on-startup>1</load-on-startup>
    </servlet>
    ou avec un Listener :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    <listener>
      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

+ Répondre à la discussion
Cette discussion est résolue.
Page 2 sur 3 PremièrePremière 123 DernièreDernière

Discussions similaires

  1. [Framework] Spring 3.1 : configuration sans XML
    Par miles_ dans le forum Spring
    Réponses: 0
    Dernier message: 13/03/2012, 10h25
  2. Configurer un pakage dans spring config ?
    Par Invité dans le forum Spring
    Réponses: 1
    Dernier message: 28/12/2006, 19h11
  3. [Hibernate | Spring ] Configuration de fichier Spring
    Par DanZzz dans le forum Hibernate
    Réponses: 1
    Dernier message: 18/06/2006, 18h58
  4. Réponses: 10
    Dernier message: 31/05/2006, 16h15

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