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 :

No bean name .. is defined


Sujet :

Spring Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Avril 2006
    Messages
    197
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2006
    Messages : 197
    Par défaut No bean name .. is defined
    Salut à tous,

    j'ai un petit probléme de configuration on dirait.
    Des que je lance mon application de test permettant de verifier le bon fonctionnement de la partie spring hibernate,il n'arrive pas à trouver le bean spingTestService

    Voici le code :

    [Main.java]
    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
     
    public class Main {
     
        /** Creates a new instance of Main */
        public Main() {
        }
        static public void  main(String[] args) {
            try{
                Personne personne = new Personne("nom", "prenom", "rue toto", 75001d);
                ApplicationContext context = new ClassPathXmlApplicationContext(new String("*.xml"));
                TestServiceImpl service = (TestServiceImpl) context.getBean("springTestService");
                service.Service(personne);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    [appContext.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
    47
    48
    49
    50
    51
    52
    53
    54
    55
     
    <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
     
    <!-- CONFIGURATION SPRING -->
     
    <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/aop
           http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
           http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
     
        <!-- service test --><!--setHibernateDao(de l'objet testHibernateDao)-->
        <bean id="springTestService" class="TestServiceImpl">
            <property name="hibernateDao" ref="testHibernateDao"/>
        </bean>
     
        <!-- hibernate dao --><!--setSessionFactory(de l'objet mysessionFactory)-->
        <bean id="testHibernateDao" class="TestHibernateDao">
            <property name="sessionFactory" ref="mySessionFactory" />
        </bean>
     
     
        <!-- configuration datasource & sessionFactory -->
        <bean id="mySessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
            <property name="dataSource">
                <ref bean ="myDataSource"/>
            </property>
            <property name="annotatedClasses">
                <list>
                    <value>Personne</value>
                </list>
            </property>
            <property name="hibernateProperties">
                <map>
                    <entry key="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
                    <entry key="hibernate.show_sql" value="true" />
                    <entry key="hibernate.hbm2ddl.auto" value="update" />
                </map>
            </property>
        </bean>
     
     
        <bean id="myDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
            <property name="driverClassName" value="org.hsqldb.jdbcDriver" />
            <property name="url" value="jdbc:hsqldb:hsql://localhost/DB" />
            <property name="username" value="sa" />
            <property name="password" value="" />
        </bean>
     
    </beans>
    [faces-config.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
     
    <?xml version='1.0'?>
    <!DOCTYPE faces-config PUBLIC "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN" "http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
     
    <!-- CONFIGURATION JSF -->
     
     
    <faces-config>
        <managed-bean>
            <managed-bean-name>controleurpers</managed-bean-name>
            <managed-bean-class>ControleurPersonne</managed-bean-class>
            <managed-property>
                <property-name>springTestService</property-name>
                <value>#{springTestService}</value>
            </managed-property>
            <managed-bean-scope>request</managed-bean-scope>
        </managed-bean>
        <application>
            <variable-resolver>
                org.springframework.web.jsf.DelegatingVariableResolver
            </variable-resolver>
            <locale-config />
        </application>    
        <lifecycle/>
        <factory/>
    </faces-config>
    [web.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
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
     
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" 
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
     
        <context-param>
            <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
            <param-value>server</param-value>        
        </context-param>
     
        <context-param>
            <param-name>javax.faces.CONFIG_FILES</param-name>
            <param-value>/WEB-INF/faces-config.xml</param-value>
        </context-param>
     
        <context-param>
            <param-name>com.sun.faces.validateXml</param-name>
            <param-value>true</param-value>
        </context-param>
     
        <context-param>
            <param-name>com.sun.faces.verifyObjects</param-name>
            <param-value>false</param-value>
        </context-param>
     
        <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener> 
     
        <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/appContext.xml</param-value>
        </context-param>    
     
        <servlet>
            <servlet-name>Faces Servlet</servlet-name>
            <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
            <load-on-startup>1</load-on-startup>
        </servlet>
     
        <servlet>
            <servlet-name>SpringContextServlet</servlet-name>
            <servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
            <load-on-startup>1</load-on-startup>
        </servlet>
     
        <servlet-mapping>
            <servlet-name>Faces Servlet</servlet-name>
            <url-pattern>/faces/*</url-pattern>
        </servlet-mapping>
        
        <welcome-file-list>
            <welcome-file>faces/index.jsp</welcome-file>
        </welcome-file-list>
        
        <jsp-config>
            <jsp-property-group>
                <url-pattern>*.jspf</url-pattern>
                <is-xml>true</is-xml>
            </jsp-property-group>
        </jsp-config>
    </web-app>
    S'il vous manque des informations,n'hésitez pas

    Merci de votre aide

  2. #2
    Membre Expert Avatar de maxf1
    Profil pro
    Inscrit en
    Novembre 2006
    Messages
    1 229
    Détails du profil
    Informations personnelles :
    Âge : 40
    Localisation : France, Moselle (Lorraine)

    Informations forums :
    Inscription : Novembre 2006
    Messages : 1 229
    Par défaut
    Je vois 2 raisons probables, la premiere il arrive pas à récupérer le xml:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    static public void  main(String[] args) {
            try{
                Personne personne = new Personne("nom", "prenom", "rue toto", 75001d);
                ApplicationContext context = new ClassPathXmlApplicationContext(new String("*.xml"));
                TestServiceImpl service = (TestServiceImpl) context.getBean("springTestService");
                service.Service(personne);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    Essaye de mettre vraiment le nom de ton fichier de conf xml.

    Sinon dans ton fichier xml tu met :


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    <bean id="springTestService" class="TestServiceImpl">
            <property name="hibernateDao" ref="testHibernateDao"/>
        </bean>
    La classe TestServiceImpl est-elle dans un package? Si oui precise le.


    Si ce n'est pas 1 des 2 solutions donne nous l'erreur exact qu'il te donne (la stacktrace assez complete)

  3. #3
    Membre confirmé
    Profil pro
    Inscrit en
    Avril 2006
    Messages
    197
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2006
    Messages : 197
    Par défaut
    A mon avis,ca vient plutot de la premiére solution

    Voici le message d'erreur qui me met
    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
     
    init:
    deps-module-jar:
    deps-ear-jar:
    deps-jar:
    Compiling 1 source file to C:\Documents and Settings\sdane\Bureau\workspace\JSF_HIBERNATE_SPRING\build\web\WEB-INF\classes
    compile-single:
    run-main:
    11:49:45,639  INFO CollectionFactory:73 - JDK 1.4+ collections available
    11:49:45,639  INFO CollectionFactory:73 - JDK 1.4+ collections available
    11:49:45,639  INFO CollectionFactory:76 - Commons Collections 3.x available
    11:49:45,639  INFO CollectionFactory:76 - Commons Collections 3.x available
    11:49:45,702  INFO ClassPathXmlApplicationContext:100 - Bean factory for application context [org.springframework.context.support.ClassPathXmlApplicationContext;hashCode=56667]: org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans []; root of BeanFactory hierarchy
    11:49:45,702  INFO ClassPathXmlApplicationContext:100 - Bean factory for application context [org.springframework.context.support.ClassPathXmlApplicationContext;hashCode=56667]: org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans []; root of BeanFactory hierarchy
    11:49:45,702  INFO ClassPathXmlApplicationContext:319 - No beans defined in application context [org.springframework.context.support.ClassPathXmlApplicationContext;hashCode=56667]
    11:49:45,702  INFO ClassPathXmlApplicationContext:319 - No beans defined in application context [org.springframework.context.support.ClassPathXmlApplicationContext;hashCode=56667]
    11:49:45,702  INFO ClassPathXmlApplicationContext:473 - Unable to locate MessageSource with name 'messageSource': using default [org.springframework.context.support.DelegatingMessageSource@eee36c]
    11:49:45,702  INFO ClassPathXmlApplicationContext:473 - Unable to locate MessageSource with name 'messageSource': using default [org.springframework.context.support.DelegatingMessageSource@eee36c]
    11:49:45,717  INFO ClassPathXmlApplicationContext:495 - Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using default [org.springframework.context.event.SimpleApplicationEventMulticaster@8ed465]
    11:49:45,717  INFO ClassPathXmlApplicationContext:495 - Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using default [org.springframework.context.event.SimpleApplicationEventMulticaster@8ed465]
    11:49:45,717  INFO DefaultListableBeanFactory:261 - Pre-instantiating singletons in factory [org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans []; root of BeanFactory hierarchy]
    11:49:45,717  INFO DefaultListableBeanFactory:261 - Pre-instantiating singletons in factory [org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans []; root of BeanFactory hierarchy]
    Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'springTestService' is defined
            at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:340)
            at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedBeanDefinition(AbstractBeanFactory.java:906)
            at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:242)
            at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:161)
            at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:642)
            at Main.main(Main.java:25)
    Java Result: 1
    Etant donné que j'utilise netbeans et que les fichiers sont rangés dans des répertoires précis,dans le fichier main des que je fais ApplicationContext context = new ClassPathXmlApplicationContext(new String("*.xml"));
    ,à mon avis il recherche directement dans ce repertoire,j'ai essayé directement avec "../../web/Web-INF/*.xml" ,il n'aime pas donc....

    Pour info,aucun package

    En essayant ceci : ApplicationContext context = new ClassPathXmlApplicationContext(new String("../../web/WEB-INF/*.xml"));


    Voici le résultat
    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
     
    init:
    deps-module-jar:
    deps-ear-jar:
    deps-jar:
    Compiling 1 source file to C:\Documents and Settings\sdane\Bureau\workspace\JSF_HIBERNATE_SPRING\build\web\WEB-INF\classes
    compile-single:
    run-main:
    12:05:26,990  INFO CollectionFactory:73 - JDK 1.4+ collections available
    12:05:26,990  INFO CollectionFactory:73 - JDK 1.4+ collections available
    12:05:26,990  INFO CollectionFactory:76 - Commons Collections 3.x available
    12:05:26,990  INFO CollectionFactory:76 - Commons Collections 3.x available
    Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: Could not resolve bean definition resource pattern [../../web/WEB-INF/*.xml]; nested exception is java.io.FileNotFoundException: class path resource [../../web/WEB-INF/] cannot be resolved to URL because it does not exist
    Caused by: java.io.FileNotFoundException: class path resource [../../web/WEB-INF/] cannot be resolved to URL because it does not exist
            at org.springframework.core.io.ClassPathResource.getURL(ClassPathResource.java:155)
            at org.springframework.core.io.support.PathMatchingResourcePatternResolver.isJarResource(PathMatchingResourcePatternResolver.java:366)
            at org.springframework.core.io.support.PathMatchingResourcePatternResolver.findPathMatchingResources(PathMatchingResourcePatternResolver.java:317)
            at org.springframework.core.io.support.PathMatchingResourcePatternResolver.getResources(PathMatchingResourcePatternResolver.java:255)
            at org.springframework.context.support.AbstractApplicationContext.getResources(AbstractApplicationContext.java:772)
            at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:140)
            at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:167)
            at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:113)
            at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:79)
            at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:94)
            at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:292)
            at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:92)
            at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:77)
            at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:68)
            at Main.main(Main.java:24)
    Java Result: 1
    Et meme j'avais essayé de mettre directement les fichiers xml,la ou sont rangés les fichiers java,meme erreur donc,ca ne doit pas vennir en fait de la premiere solution lol

  4. #4
    Membre Expert Avatar de maxf1
    Profil pro
    Inscrit en
    Novembre 2006
    Messages
    1 229
    Détails du profil
    Informations personnelles :
    Âge : 40
    Localisation : France, Moselle (Lorraine)

    Informations forums :
    Inscription : Novembre 2006
    Messages : 1 229
    Par défaut
    Quand je dis met le nom de ton fichier je parle du nom du fichier (ca semble logique mais apparement non) et non pas du path du fichier.


    Donc ne met pas ../..//.//WEB-INF/*.xml

    Mais monfichiersapellecommca.xml

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    ApplicationContext context = new ClassPathXmlApplicationContext("mofichiersappellecommeca.xml");
    Le new String tu peux t'en passer.

  5. #5
    Membre confirmé
    Profil pro
    Inscrit en
    Avril 2006
    Messages
    197
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2006
    Messages : 197
    Par défaut
    En essayant ce que tu m'as dit ApplicationContext context = new ClassPathXmlApplicationContext("appContext.xml");

    Ca donne ce message d'erreur
    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
     
    init:
    deps-module-jar:
    deps-ear-jar:
    deps-jar:
    Compiling 1 source file to C:\Documents and Settings\sdane\Bureau\workspace\JSF_HIBERNATE_SPRING\build\web\WEB-INF\classes
    compile-single:
    run-main:
    12:10:36,060  INFO CollectionFactory:73 - JDK 1.4+ collections available
    12:10:36,060  INFO CollectionFactory:73 - JDK 1.4+ collections available
    12:10:36,076  INFO CollectionFactory:76 - Commons Collections 3.x available
    12:10:36,076  INFO CollectionFactory:76 - Commons Collections 3.x available
    12:10:36,123  INFO XmlBeanDefinitionReader:330 - Loading XML bean definitions from class path resource [appContext.xml]
    12:10:36,123  INFO XmlBeanDefinitionReader:330 - Loading XML bean definitions from class path resource [appContext.xml]
    Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [appContext.xml]; nested exception is java.io.FileNotFoundException: class path resource [appContext.xml] cannot be opened because it does not exist
    Caused by: java.io.FileNotFoundException: class path resource [appContext.xml] cannot be opened because it does not exist
            at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:135)
            at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
            at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:317)
            at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:125)
            at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:141)
            at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:167)
            at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:113)
            at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:79)
            at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:94)
            at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:292)
            at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:92)
            at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:77)
            at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:68)
            at Main.main(Main.java:24)
    Java Result: 1
    BUILD SUCCESSFUL (total time: 1 second)

  6. #6
    Membre Expert Avatar de maxf1
    Profil pro
    Inscrit en
    Novembre 2006
    Messages
    1 229
    Détails du profil
    Informations personnelles :
    Âge : 40
    Localisation : France, Moselle (Lorraine)

    Informations forums :
    Inscription : Novembre 2006
    Messages : 1 229
    Par défaut
    Ton fichier est dans WEB-INF?
    Ou dans WEB-INF/classes?

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

Discussions similaires

  1. Erreur "No bean named is defined"
    Par grassol dans le forum Spring
    Réponses: 2
    Dernier message: 13/06/2013, 20h52
  2. [Security] No bean named 'springSecurityFilterChain' is defined
    Par jackRackham dans le forum Spring
    Réponses: 0
    Dernier message: 03/08/2011, 11h57
  3. No bean named 'anyBean' is defined
    Par peipsy dans le forum Services Web
    Réponses: 1
    Dernier message: 01/07/2011, 18h30
  4. Réponses: 1
    Dernier message: 15/04/2009, 21h06

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