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 Web Java Discussion :

J2EE Spring - Annotations non prises en compte


Sujet :

Spring Web Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Nouveau membre du Club
    Homme Profil pro
    Ingénieur logiciel (WinDev)
    Inscrit en
    Juillet 2014
    Messages
    6
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : France, Tarn (Midi Pyrénées)

    Informations professionnelles :
    Activité : Ingénieur logiciel (WinDev)
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2014
    Messages : 6
    Par défaut J2EE Spring - Annotations non prises en compte
    Bonsoir amis développeurs,

    (Contexte - Vous pouvez vous rediriger vers la section Demande si vous ne souhaitez pas perdre de temps.)
    Récemment, j'ai suivi de nombreux tutoriels pour me lancer dans la création d'un site internet en J2EE.
    Basée sur les Frameworks Spring, Hibernate et Primefaces, l'application évolue lentement mais sûrement...
    C'est alors que j'ai été confronté à l'utilisation des annotations avec Spring.
    J'ai vu de nombreux sujets sur le forum developpez.net qui parlaient de ses fameuses annotations, et ai pu rectifier quelques erreurs.
    Typiquement, je n'avais pas activé la gestion des annotations dans Spring.
    Malgré le parcours de X tutoriels sur Spring, je ne parviens toujours pas à faire fonctionner les annotations d'injection.
    J'ai ajouté ces deux lignes dans le fichier de configuration de Spring (applicationContext.xml) :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    <context:component-scan base-package="com.mickaelcalmettes.siteweb" />
    <context:annotation-config />
    Je n'ai pas déclaré ces balises ailleurs (car apparemment cela pose problème de scanner plusieurs fois le projet).

    (Demande)
    Concrètement, j'ai annoté tous mes DAOImpl avec l'annotation @Repository("nomDuDAO"), tous mes ServiceImpl avec l'annotation @Service("nomDuService"), et toutes mes références aux IDAO et IServices avec @Autowired.
    J'ai créé un backing bean qui appelle un service de test, et lors de cet appel, je reçois un NullPointerException.
    Les détails ci-après.

    (Informations sur le code)
    La vue :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    <h:commandButton value="Test création catégorie avec todos inexistants" action="#{testHibernateBean.creerCategorie()}" />
    <h:commandButton value="Test création todo avec une catégorie inexistante" action="#{testHibernateBean.creerTodo()}" />
    Ces boutons appelent le backingBean "TestHibernateBean" :
    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
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    @ManagedBean(name = "testHibernateBean")
    @ViewScoped
    public class TestHibernateBean implements Serializable {
        private Categorie categorie1;
        private final Set<TodoMemo> todoSet = new HashSet();
        private TodoMemo todo;
        private Categorie categorie2;
        @Autowired
        private ITodoService todoService;
        @Autowired
        private ICategorieService categorieService;
     
        @PostConstruct
        public void init() {
            this.initTests();
        }
     
        private void initTests() {
            // Création du jeu de données
            categorie1 = new Categorie();
            categorie2 = new Categorie();
            categorie1.setLibelleCategorie("Catégorie avec plusieurs TODO");
            categorie2.setLibelleCategorie("Catégorie avec un seul TODO");
            todo = new TodoMemo();
            todo.setDateTodo(new Date());
            todo.setPriorite(5);
            todo.setTodo("Todo relié à la catégorie 'Catégorie avec un seul TODO'");
            for(int i=1 ; i<5 ; i++){
                TodoMemo tempTodo = new TodoMemo();
                tempTodo.setDateTodo(new Date());
                tempTodo.setPriorite(i);
                tempTodo.setTodo("Todo relié à la catégorie 'Catégorie avec plusieurs TODO' n°" + i);
                todoSet.add(tempTodo);
            }
     
            // Liaisons
            categorie1.setTodo(todoSet);
            todo.setCategorie(categorie2);
        }
     
        public void creerCategorie(){
            // Test création catégorie avec plusieurs TODO associés
            categorieService.saveCategorie(categorie1);
        }
     
        public void creerTodo(){
            // Test création todo avec catégorie associée
            todoService.saveTodo(todo);
        }
     
        public Categorie getCategorie1() {
            return categorie1;
        }
     
        public void setCategorie1(Categorie categorie1) {
            this.categorie1 = categorie1;
        }
     
        public TodoMemo getTodo() {
            return todo;
        }
     
        public void setTodo(TodoMemo todo) {
            this.todo = todo;
        }
     
        public Categorie getCategorie2() {
            return categorie2;
        }
     
        public void setCategorie2(Categorie categorie2) {
            this.categorie2 = categorie2;
        }
     
        public ITodoService getTodoService() {
            return todoService;
        }
     
        public void setTodoService(ITodoService todoService) {
            this.todoService = todoService;
        }
     
        public ICategorieService getCategorieService() {
            return categorieService;
        }
     
        public void setCategorieService(ICategorieService categorieService) {
            this.categorieService = categorieService;
        }
     
     
    }
    Lors de l'appel de l'une des deux méthodes creerCategorie() ou creerTodo(), Spring ne parvient pas à retrouver le service appelé malgré les annotations.
    Il me génère un NullPointerException (au besoin je peux insérer la trace de l'erreur). J'ai testé d'appeler le service via le service implémenté (CategorieServiceImpl par exemple), et il n'y a plus d'erreur. Enfin, si, mais le NullPointerException se génère dans le service lors de l'appel du DAO.

    Voici l'interface du service "ICategorieService" :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    public interface ICategorieService {
        public void saveCategorie(Categorie categorie);
    }
    Voici le service "CategorieServiceImpl" qui devrait être appelé par Spring grâce aux annotations :
    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
    @Service("categorieService")
    public class CategorieServiceImpl implements ICategorieService {
     
        @Autowired
        ICategorieDAO categorieDAO;
     
        @Override
        public void saveCategorie(Categorie categorie) {
            categorieDAO.saveCategorie(categorie);
        }
     
        public ICategorieDAO getCategorieDAO() {
            return categorieDAO;
        }
     
        public void setCategorieDAO(ICategorieDAO categorieDAO) {
            this.categorieDAO = categorieDAO;
        }
     
    }
    Et enfin, voici les fichiers de configuration.
    "applicationContext.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
    <?xml version='1.0' encoding='UTF-8' ?>
    <!-- was: <?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:p="http://www.springframework.org/schema/p"
        xmlns:context="http://www.springframework.org/schema/context"
     
        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
        ">
     
        <context:component-scan base-package="com.mickaelcalmettes.siteweb" />
        <context:annotation-config />
     
    <!--    <bean id="categorieDAO" class="com.mickaelcalmettes.siteweb.dao.impl.CategorieDAOImpl" />
        <bean id="todoDAO" class="com.mickaelcalmettes.siteweb.dao.impl.TodoDAOImpl" />
        <bean id="categorieService" class="com.mickaelcalmettes.siteweb.services.impl.CategorieServiceImpl" />
        <bean id="todoService" class="com.mickaelcalmettes.siteweb.services.impl.TodoServiceImpl" />-->
     
    </beans>
    "dispatcher-servlet.xml" : Je ne me sers pas de ce fichier de configuration, il a été créé automatiquement par Netbeans. Je peux fournir le code au besoin.

    "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
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
        <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/applicationContext.xml</param-value>
        </context-param>
        <context-param>
            <param-name>javax.faces.PROJECT_STAGE</param-name>
            <param-value>Development</param-value>
        </context-param>
        <context-param>
            <param-name>CONFIG_PATH</param-name>
            <param-value>/WEB-INF</param-value>
        </context-param>
        <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>
        <servlet>
            <servlet-name>dispatcher</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <load-on-startup>2</load-on-startup>
        </servlet>
        <servlet>
            <servlet-name>Faces Servlet</servlet-name>
            <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
            <load-on-startup>1</load-on-startup>
        </servlet>
        <servlet-mapping>
            <servlet-name>dispatcher</servlet-name>
            <url-pattern>*.*</url-pattern>
        </servlet-mapping>
        <servlet-mapping>
            <servlet-name>Faces Servlet</servlet-name>
            <url-pattern>*.xhtml</url-pattern>
        </servlet-mapping>
        <session-config>
            <session-timeout>
                30
            </session-timeout>
        </session-config>
        <welcome-file-list>
            <welcome-file>Pages/Tests/pageTestTemplateAccueil.xhtml</welcome-file>
        </welcome-file-list>
    </web-app>
    Merci beaucoup par avance de votre aide.
    Je m'excuse de la longueur du message, je tenais à le rendre le plus clair possible.
    En vous souhaitant une agréable soirée,
    M20K8X.

  2. #2
    Membre Expert Avatar de jeffray03
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2008
    Messages
    1 501
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Allemagne

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 501
    Par défaut
    salut,
    ceci tu le mets dans ton dispatcher-servlet.xml
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    <context:component-scan base-package="com.mickaelcalmettes.siteweb" />
    Eric

  3. #3
    Nouveau membre du Club
    Homme Profil pro
    Ingénieur logiciel (WinDev)
    Inscrit en
    Juillet 2014
    Messages
    6
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : France, Tarn (Midi Pyrénées)

    Informations professionnelles :
    Activité : Ingénieur logiciel (WinDev)
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2014
    Messages : 6
    Par défaut
    Bonjour Eric,

    Je te remercie de ton aide.
    Cependant, l'erreur persiste et n'a pas changé malgré le déplacement du scan des beans depuis le fichier applicationContext.xml vers le fichier dispatcher-servlet.xml.

    applicationContext.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
    <?xml version='1.0' encoding='UTF-8' ?>
    <!-- was: <?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:p="http://www.springframework.org/schema/p"
        xmlns:context="http://www.springframework.org/schema/context"
     
        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
        ">
     
        <context:annotation-config />
     
    <!--    <bean id="categorieDAO" class="com.mickaelcalmettes.siteweb.dao.impl.CategorieDAOImpl" />
        <bean id="todoDAO" class="com.mickaelcalmettes.siteweb.dao.impl.TodoDAOImpl" />
        <bean id="categorieService" class="com.mickaelcalmettes.siteweb.services.impl.CategorieServiceImpl" />
        <bean id="todoService" class="com.mickaelcalmettes.siteweb.services.impl.TodoServiceImpl" />-->
     
    </beans>
    dispatcher-servler.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
    <?xml version='1.0' encoding='UTF-8' ?>
    <!-- was: <?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:p="http://www.springframework.org/schema/p"
        xmlns:context="http://www.springframework.org/schema/context"
     
        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
        ">
     
        <!--<mvc:resources mapping="/resources/**" location="/resources/mytheme/" />-->
    <!--    <context:component-scan base-package="com.mickaelcalmettes.siteweb" />
        <context:annotation-config />-->
        <context:component-scan base-package="com.mickaelcalmettes.siteweb" />
     
        <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">  
            <property name="locations">
                <list>
                    <!--<value>file:${CONFIG_PATH}/Messages.properties</value>-->
                    <value>classpath:Messages.properties</value>
                </list>
            </property>
        </bean> 
     
        <bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>
        <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
            <property name="mappings">
                <props>
                    <prop key="index.htm">indexController</prop>
                </props>
            </property>
        </bean>
     
        <bean id="viewResolver"
              class="org.springframework.web.servlet.view.InternalResourceViewResolver"
              p:prefix="/WEB-INF/jsp/"
              p:suffix=".jsp" />
     
        <!--
        The index controller.
        -->
        <bean name="indexController"
              class="org.springframework.web.servlet.mvc.ParameterizableViewController"
              p:viewName="index" />
     
    </beans>
    C'est tout de même étrange...
    A priori les annotations ne sont pas trop mauvaises puisque beaucoup de personnes procèdent comme ceci, et normalement Spring a activé les annotations et scanné mes beans stéréotypés...

    Le message d'erreur si cela peut aider :
    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
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    03-Jul-2014 17:35:55.092 WARNING [http-nio-8084-exec-10] com.sun.faces.lifecycle.InvokeApplicationPhase.execute #{testHibernateBean.creerCategorie()}: java.lang.NullPointerException
     javax.faces.FacesException: #{testHibernateBean.creerCategorie()}: java.lang.NullPointerException
    	at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118)
    	at javax.faces.component.UICommand.broadcast(UICommand.java:315)
    	at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
    	at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
    	at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    	at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    	at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
    	at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:301)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    	at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:136)
    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:74)
    	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:516)
    	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1015)
    	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:652)
    	at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
    	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1575)
    	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1533)
    	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    	at java.lang.Thread.run(Thread.java:745)
    Caused by: javax.faces.el.EvaluationException: java.lang.NullPointerException
    	at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:101)
    	at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
    	... 31 more
    Caused by: java.lang.NullPointerException
    	at com.mickaelcalmettes.siteweb.beans.tests.TestHibernateBean.creerCategorie(TestHibernateBean.java:63)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:483)
    	at org.apache.el.parser.AstValue.invoke(AstValue.java:261)
    	at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:277)
    	at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
    	at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
    	... 32 more
     
    03-Jul-2014 17:35:55.232 1100 [http-nio-8084-exec-10] com.sun.faces.context.ExceptionHandlerImpl.log JSF1073 : javax.faces.FacesException intercepté durant le traitement de INVOKE_APPLICATION 5 : UIComponent-ClientId=, Message=#{testHibernateBean.creerCategorie()}: java.lang.NullPointerException
    03-Jul-2014 17:35:55.232 1100 [http-nio-8084-exec-10] com.sun.faces.context.ExceptionHandlerImpl.log #{testHibernateBean.creerCategorie()}: java.lang.NullPointerException
     javax.faces.FacesException: #{testHibernateBean.creerCategorie()}: java.lang.NullPointerException
    	at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:89)
    	at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    	at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
    	at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:301)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    	at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:136)
    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:74)
    	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:516)
    	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1015)
    	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:652)
    	at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
    	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1575)
    	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1533)
    	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    	at java.lang.Thread.run(Thread.java:745)
    Caused by: javax.faces.FacesException: #{testHibernateBean.creerCategorie()}: java.lang.NullPointerException
    	at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118)
    	at javax.faces.component.UICommand.broadcast(UICommand.java:315)
    	at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
    	at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
    	at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    	... 27 more
    Caused by: javax.faces.el.EvaluationException: java.lang.NullPointerException
    	at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:101)
    	at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
    	... 31 more
    Caused by: java.lang.NullPointerException
    	at com.mickaelcalmettes.siteweb.beans.tests.TestHibernateBean.creerCategorie(TestHibernateBean.java:63)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:483)
    	at org.apache.el.parser.AstValue.invoke(AstValue.java:261)
    	at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:277)
    	at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
    	at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
    	... 32 more
    Dans le pire des cas je pourrai enlever Spring du projet et ne plus passer par des interfaces.
    Merci encore pour l'aide.

    En vous souhaitant une agréable fin de journée,
    M20K8X.

  4. #4
    Membre Expert Avatar de jeffray03
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2008
    Messages
    1 501
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Allemagne

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 501
    Par défaut
    dans quels packages sont declarées tes classes?

  5. #5
    Nouveau membre du Club
    Homme Profil pro
    Ingénieur logiciel (WinDev)
    Inscrit en
    Juillet 2014
    Messages
    6
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : France, Tarn (Midi Pyrénées)

    Informations professionnelles :
    Activité : Ingénieur logiciel (WinDev)
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2014
    Messages : 6
    Par défaut
    Bonsoir Eric,

    Voici l'arborescence de mon projet :
    Nom : arborescenceClasspath.png
Affichages : 407
Taille : 20,5 Ko

    Mes classes sont bien présentes dans un des sous-packages de "com.mickaelcalmettes.siteweb"...

    Point très intéressant !!! J'ai donc fait des tests en changeant l'emplacement du scan de packages, et je suis arrivé à un résultat très concluant :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.mickaelcalmettes.siteweb.dao.ICategorieDAO com.mickaelcalmettes.siteweb.services.impl.CategorieServiceImpl.categorieDAO
    Cette erreur est normale, puisque je disais à Spring dans le test en question de scanner le sous-package "services". Pourquoi est-ce intéressant ? Parce que cela signifie que les annotations de Spring sont bien prises en compte ! Si je n'ai pas d'erreurs en temps normal, c'est que Spring arrive probablement à "Autowired" les beans...
    Donc déjà une partie du problème écartée : Spring annote bien les beans. Reste à savoir pourquoi alors il génère un NullPointerException quand je tente d'appeler un service ou un DAO en passant par l'interface...

    Merci Eric, ton post a déjà un peu éclairci le problème : Spring semble bien charger les beans !

    Passe une agréable soirée,
    M20K8X.

  6. #6
    Membre Expert Avatar de jeffray03
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2008
    Messages
    1 501
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Allemagne

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 501
    Par défaut
    salut,
    peux-tu nous montrer comment tu as implementé CategorieDAOImpl?

    eric

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

Discussions similaires

  1. [Data] [Spring][Ibatis] transactions non prise en compte
    Par nannous dans le forum Spring
    Réponses: 15
    Dernier message: 27/11/2007, 18h01
  2. Installation SP2 + RAM non prise en compte
    Par laure_belette dans le forum Windows XP
    Réponses: 3
    Dernier message: 13/10/2005, 12h46
  3. [css] Feuille de style non prise en compte
    Par Neuromancien2 dans le forum Mise en page CSS
    Réponses: 4
    Dernier message: 29/06/2005, 11h49
  4. [netbeans] Modifications non prises en compte
    Par nadass dans le forum NetBeans
    Réponses: 6
    Dernier message: 07/04/2005, 13h49
  5. Lecture de fichier - dernière ligne non prise en compte
    Par JulienPles dans le forum Algorithmes et structures de données
    Réponses: 3
    Dernier message: 16/03/2005, 11h57

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