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

Servlets/JSP Java Discussion :

[spring] comment referencer un bean existant dans applicationContext.xml


Sujet :

Servlets/JSP Java

  1. #1
    Membre du Club
    Inscrit en
    Mars 2006
    Messages
    103
    Détails du profil
    Informations forums :
    Inscription : Mars 2006
    Messages : 103
    Points : 49
    Points
    49
    Par défaut [spring] comment referencer un bean existant dans applicationContext.xml
    bonjour,
    si qlq un a une idée sur la source de ce prb ca vas vraiment me débloqué.
    j ai un bean servive ds le fichier applicationContext.xml que j utilise dans un autre fichier test1-servlet.xml , qd lance la page d acceuil de mon application j ai ce message :
    org.springframework.beans.factory.BeanCreationException:
    Error creating bean with name 'Personnes.ListController'
    defined in ServletContext resource [/WEB-INF/test1-servlet.xml]:
    Cannot resolve reference to bean 'service'
    while setting bean property 'service'
    exception is org.springframework.beans.factory.NoSuchBeanDefinit
    ionException: No bean named 'service' is defined

    je vois pas comment faire pour ajouter applicationContext.xml ds la classpath du projet pour l exploiter ds test1-servlet.xml!!!!Merci pour votre aide

  2. #2
    Membre expérimenté
    Avatar de zekey
    Profil pro
    Inscrit en
    Février 2005
    Messages
    1 036
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2005
    Messages : 1 036
    Points : 1 403
    Points
    1 403
    Par défaut
    Comment effectues tu le wiring up de spring au départ ?

  3. #3
    Membre du Club
    Inscrit en
    Mars 2006
    Messages
    103
    Détails du profil
    Informations forums :
    Inscription : Mars 2006
    Messages : 103
    Points : 49
    Points
    49
    Par défaut
    qu est ce que tu veux dir par: le wiring up de spring au départ ???

  4. #4
    Membre du Club
    Inscrit en
    Mars 2006
    Messages
    103
    Détails du profil
    Informations forums :
    Inscription : Mars 2006
    Messages : 103
    Points : 49
    Points
    49
    Par défaut le fichier applicationContext.xml
    <?xml version="1.0" encoding="ISO_8859-1"?>
    <!--Ce fichier est exploité par le listener [ContextLoaderListener] avant même que [DispatcherServlet] ne soit instancié.-->

    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
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    <!DOCTYPE beans SYSTEM "http://www.springframework.org/dtd/spring-beans.dtd">
    <beans>
     
        <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" 
            destroy-method="close">
            <property name="driverClassName">
                <value>org.firebirdsql.jdbc.FBDriver</value>
            </property>
            <property name="url">
                <!-- attention : ne pas laisser d'espaces entre les deux balises <value> -->
                <value>jdbc:firebirdsql:localhost/3050:C:\Documents and Settings\Stage\Bureau\database\DBPERSONNES.GDB</value>
            </property>
            <property name="username">
                <value>sysdba</value>
            </property>
            <property name="password">
                <value>masterkey</value>
            </property>
        </bean>
     
        <bean id="sqlMapClient" 
            class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
            <property name="dataSource"><!--[DataSource] connecté à la base de données-->
                <ref local="dataSource"/>
            </property>
            <property name="configLocation"><!--fichier de configuration où sont externalisés les ordres SQL à exécuter-->
                <value>classpath:sql-map-config-firebird.xml</value>
            </property>
        </bean>
        <!-- la classes d'accès à la couche [dao] -->
     
        <bean id="dao" class="code.dao.DaoImplCommon">
            <property name="sqlMapClient">
                <ref local="sqlMapClient"/>
            </property>
        </bean>
     
        <!-- gestionnaire de transactions -->
        <bean id="transactionManager" 
            class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
            <property name="dataSource">
                <ref local="dataSource"/>
            </property>
        </bean>
        <!-- la classes d'accès à la couche [service] page 35 -->
        <bean id="service" 
            class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
            <property name="transactionManager">
                <ref local="transactionManager"/>
            </property>
            <property name="target">
     
                <bean class="code.service.ServiceImpl">
                    <property name="dao">
                        <ref local="dao"/>
                    </property>
                </bean>
            </property>
            <property name="transactionAttributes">
                <!--indique quelles méthodes de [ServiceImpl] nécessitent une transaction et quels sont les attributs de celle-ci-->
                <props>
                    <prop key="get*">PROPAGATION_SUPPORTS,readOnly</prop>
                    <prop key="save*">PROPAGATION_REQUIRED</prop>
                    <prop key="delete*">PROPAGATION_REQUIRED</prop>
                </props>
            </property>
        </bean>
     
    </beans>

  5. #5
    Membre du Club
    Inscrit en
    Mars 2006
    Messages
    103
    Détails du profil
    Informations forums :
    Inscription : Mars 2006
    Messages : 103
    Points : 49
    Points
    49
    Par défaut test1-servlet.xml
    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
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
    <beans>
        <!-- les mappings de l'application-->
        <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
            <property name="mappings">
                <props>
                    <prop key="/formulaire.html">Test1Controller</prop>
                    <prop key="/list.html">Personnes.ListController</prop>
                </props>
            </property>
        </bean>
        <!-- les contrôleurs de l'application-->
        <bean id="Personnes.ListController" 
            class="code.web.ListPersonnes">
           
            
            <property name="service">
            <ref bean="service"/>
            </property>
        </bean>
        <bean id="Test1Controller"
            class="org.springframework.web.servlet.mvc.SimpleFormController">
            <property name="sessionForm">
                <value>true</value>
            </property>
            <property name="commandClass">
                <value>code.web.Formulaire</value>
            </property>
            <property name="commandName">
                <value>formulaire</value>
            </property>
            <property name="formView">
                <value>formulaire</value>
            </property>
            
            
        </bean>
        <!-- le résolveur de vues -->
        <bean class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
            <property name="basename">
                <value>vues</value>
            </property>
        </bean>
        
    </beans>

  6. #6
    Membre expérimenté
    Avatar de zekey
    Profil pro
    Inscrit en
    Février 2005
    Messages
    1 036
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2005
    Messages : 1 036
    Points : 1 403
    Points
    1 403
    Par défaut
    Un truc du genre:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext*.xml</param-value>
    </context-param>
     
    <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

  7. #7
    Membre du Club
    Inscrit en
    Mars 2006
    Messages
    103
    Détails du profil
    Informations forums :
    Inscription : Mars 2006
    Messages : 103
    Points : 49
    Points
    49
    Par défaut
    je l ai pas je doit mettre kwa et où c ma premiere application que je suis entrain de faire

  8. #8
    Membre expérimenté
    Avatar de zekey
    Profil pro
    Inscrit en
    Février 2005
    Messages
    1 036
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2005
    Messages : 1 036
    Points : 1 403
    Points
    1 403
    Par défaut
    La je ne comprend plus. Comment fais tu pour utiliser spring ? Quel est le point d'entrée ?

  9. #9
    Membre du Club
    Inscrit en
    Mars 2006
    Messages
    103
    Détails du profil
    Informations forums :
    Inscription : Mars 2006
    Messages : 103
    Points : 49
    Points
    49
    Par défaut
    je me base sur le tutoriel de serge tahé, j ai utiliser les librairies qui sont ds ses projets. comment je doit faire ce waring up. ds son tuto il n as pas parlé de ça

  10. #10
    Membre expérimenté
    Avatar de zekey
    Profil pro
    Inscrit en
    Février 2005
    Messages
    1 036
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2005
    Messages : 1 036
    Points : 1 403
    Points
    1 403
    Par défaut
    Quel tutorial ?

  11. #11
    Membre du Club
    Inscrit en
    Mars 2006
    Messages
    103
    Détails du profil
    Informations forums :
    Inscription : Mars 2006
    Messages : 103
    Points : 49
    Points
    49

  12. #12
    Membre du Club
    Inscrit en
    Mars 2006
    Messages
    103
    Détails du profil
    Informations forums :
    Inscription : Mars 2006
    Messages : 103
    Points : 49
    Points
    49
    Par défaut
    J ai ajouter ce code dans mon fichier web.xml est ca marche :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    <listener>
            <listener-class> 
        <!--une classe Spring chargée d'initialiser le contexte de-->
    <!-- l'application web en lisant le contenu du fichier [WEB-INF/applicationContext.xml]-->    
                org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>


    Merci bcp pour votre aide

  13. #13
    Membre expérimenté
    Avatar de zekey
    Profil pro
    Inscrit en
    Février 2005
    Messages
    1 036
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2005
    Messages : 1 036
    Points : 1 403
    Points
    1 403
    Par défaut
    Pour les classes de tests à la page 20
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    13. IDao dao = (IDao) (new XmlBeanFactory(new ClassPathResource(
    14. "spring-config-test-dao-firebird.xml"))).getBean("dao");
    La il effectue le wiring up avec le fichier de config:spring-config-test-dao-firebird.xml

    Spring prend le fichier applicationContext.xml par défault si tu ne spécifie rien. si tu as plusieurs fichiers utilise la facon suivant en nommant tes fichiers applicationContext1.xml, applicationContext2.xml, applicationContextToto.xml,....

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext*.xml</param-value>
    </context-param>
     
    <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Comment ajouter un bean message dans un attribut de custom tag ?
    Par Battosaiii dans le forum Servlets/JSP
    Réponses: 1
    Dernier message: 07/11/2011, 03h37
  2. comment changer la valeur existant dans la barre d'adresse
    Par yacine.dev dans le forum Struts 1
    Réponses: 3
    Dernier message: 23/12/2009, 13h14
  3. Controler si un noeud existe dans un XML
    Par psykodumarteau dans le forum Général VBA
    Réponses: 2
    Dernier message: 20/02/2009, 14h51
  4. Réponses: 11
    Dernier message: 12/02/2009, 10h33
  5. pb : comment connaitre les groupes existants dans une machine Linux
    Par donkeyquote dans le forum Administration système
    Réponses: 4
    Dernier message: 11/03/2008, 11h26

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