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

GWT et Vaadin Java Discussion :

GWT/Spring : pointer null exception


Sujet :

GWT et Vaadin Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Février 2010
    Messages
    53
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2010
    Messages : 53
    Par défaut GWT/Spring : pointer null exception
    Bonjour à tous.

    Voila, j'ai encore un problème avec GWT, cette fois-ci avec Spring. Mon but est de tenter d'intégrer les annotations @Autowired à moin projet.

    Je rappelle donc que j'ai un projet parent contentant 3 modules enfant, client, services et model.

    Le problème est que lorsque je met en place les annotations et que je tente de tester, j'obtiens un Java pointer null exception. Pourtant les context semblent bien chargés avec Tomcat !

    Voici donc mon code :

    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
    <?xml version="1.0" encoding="UTF-8"?>
    <!--<!DOCTYPE web-app-->
    <!--    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"-->
    <!--    "http://java.sun.com/dtd/web-app_2_3.dtd">-->
     
    <web-app id="WebApp_ID" version="2.5"
        xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
            http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
     
    <display-name>GWT-Maven-Archetype</display-name>
        <!-- Initialise the Spring web MVC DispatcherServlet -->
     
    	<context-param>
    		<param-name>contextConfigLocation</param-name>
    		<param-value>classpath*:applicationContext*.xml</param-value>
    	</context-param>
     
        <servlet>
            <servlet-name>spring</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <load-on-startup>1</load-on-startup>
        </servlet>
     
        <!-- Map the DispatcherServlet to only intercept RPC requests -->
     
        <servlet-mapping>
            <servlet-name>spring</servlet-name>
            <url-pattern>*.rpc</url-pattern>
        </servlet-mapping>
     
        <listener>
    		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    	</listener>
     
    <!--   <servlet>-->
    <!--		<servlet-name>context</servlet-name>-->
    <!--		<servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>-->
    <!--		<load-on-startup>1</load-on-startup>-->
    <!--	</servlet> -->
     
     
      <!-- Servlets -->
    <!--  <servlet>-->
    <!--    <servlet-name>greetServlet</servlet-name>-->
    <!--    <servlet-class>com.novedia.ce.services.GreetingServiceImpl</servlet-class>-->
    <!--  </servlet>-->
    <!--  -->
    <!--  <servlet-mapping>-->
    <!--    <servlet-name>greetServlet</servlet-name>-->
    <!--    <url-pattern>/ce/greet</url-pattern>-->
    <!--  </servlet-mapping>-->
     
     	<welcome-file-list>
    		<welcome-file>index.html</welcome-file>
    	</welcome-file-list>
     
    </web-app>
    applicationContext-client.xml (dans client/src/main/resources)

    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
    <?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:tx="http://www.springframework.org/schema/tx"
    	xmlns:aop="http://www.springframework.org/schema/aop"
    	xmlns:context="http://www.springframework.org/schema/context"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans 
    	http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    	http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
    	http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
    	http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
     
    	<context:annotation-config />
     
    	<context:component-scan base-package="com.novedia.ce.client"/>	
    	<context:component-scan base-package="com.novedia.ce.services"/>	
    <!--	<context:component-scan base-package="com.novedia.ce.model"/>	-->
     
    </beans>
    Mon applicationContext-services, dans services/src/main/resources

    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
    <?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:tx="http://www.springframework.org/schema/tx"
    	xmlns:aop="http://www.springframework.org/schema/aop"
    	xmlns:context="http://www.springframework.org/schema/context"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans 
    	http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    	http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
    	http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
    	http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
     
    	<context:annotation-config />
     
    	<context:component-scan base-package="com.novedia.ce.services"/>	
    <!--	<context:component-scan base-package="com.novedia.ce.model"/>	-->
     
    </beans>
    Mon code de test (classe dans services/src/maib/java/com/novedia/ce/services)

    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
    package com.novedia.ce.services;
     
     
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;
     
    @Service
    public class UserServiceImpl implements UserService {
     
    	@Autowired
    	private GreetingService greetingService;
     
    	@Override
    	public String checkLogin() {
    		greetingService.greetServer("user");
     
    		return "exist succes";
    	}
     
     
     
    }
    Je précise que l'annotation Service est bien mis sur la classe GreetingServiceImpl.

    J'obtiens alors l'erreur suivante :

    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
    3 mai 2010 12:25:09 org.springframework.web.context.ContextLoader initWebApplicationContext
    INFO: Root WebApplicationContext: initialization started
    3 mai 2010 12:25:09 org.springframework.context.support.AbstractApplicationContext prepareRefresh
    INFO: Refreshing org.springframework.web.context.support.XmlWebApplicationContext@b8f8eb: display name [Root WebApplicationContext]; startup date [Mon May 03 12:25:09 CEST 2010]; root of context hierarchy
    3 mai 2010 12:25:09 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
    INFO: Loading XML bean definitions from file [D:\workspace\ce\ce-client\target\ce\WEB-INF\classes\applicationContext-client.xml]
    3 mai 2010 12:25:10 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
    INFO: Loading XML bean definitions from file [D:\workspace\ce\ce-client\target\ce\WEB-INF\classes\applicationContext-services.xml]
    3 mai 2010 12:25:10 org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory
    INFO: Bean factory for application context [org.springframework.web.context.support.XmlWebApplicationContext@b8f8eb]: org.springframework.beans.factory.support.DefaultListableBeanFactory@1cef4f7
    3 mai 2010 12:25:10 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
    INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1cef4f7: defining beans [org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,greetingServiceImpl,userServiceImpl]; root of factory hierarchy
    3 mai 2010 12:25:10 org.springframework.web.context.ContextLoader initWebApplicationContext
    INFO: Root WebApplicationContext: initialization completed in 938 ms
    3 mai 2010 12:25:10 org.springframework.web.servlet.FrameworkServlet initServletBean
    INFO: FrameworkServlet 'spring': initialization started
    3 mai 2010 12:25:10 org.springframework.context.support.AbstractApplicationContext prepareRefresh
    INFO: Refreshing org.springframework.web.context.support.XmlWebApplicationContext@1a0225b: display name [WebApplicationContext for namespace 'spring-servlet']; startup date [Mon May 03 12:25:10 CEST 2010]; parent: org.springframework.web.context.support.XmlWebApplicationContext@b8f8eb
    3 mai 2010 12:25:10 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
    INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/spring-servlet.xml]
    3 mai 2010 12:25:10 org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory
    INFO: Bean factory for application context [org.springframework.web.context.support.XmlWebApplicationContext@1a0225b]: org.springframework.beans.factory.support.DefaultListableBeanFactory@5eb489
    3 mai 2010 12:25:10 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
    INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@5eb489: defining beans [urlMapping,userController]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory@1cef4f7
    3 mai 2010 12:25:11 org.springframework.web.servlet.FrameworkServlet initServletBean
    INFO: FrameworkServlet 'spring': initialization completed in 609 ms
    Starting Jetty on port 0
       [WARN] Exception while dispatching incoming RPC call
    com.google.gwt.user.server.rpc.UnexpectedException: Service method 'public abstract java.lang.String com.novedia.ce.services.UserService.checkLogin()' threw an unexpected exception: java.lang.NullPointerException
    	at com.google.gwt.user.server.rpc.RPC.encodeResponseForFailure(RPC.java:378)
    	at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:581)
    	at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:544)
    	at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:504)
    	at com.novedia.ce.services.GwtRpcController.processCall(GwtRpcController.java:41)
    	at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:224)
    	at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
    	at com.novedia.ce.services.GwtRpcController.handleRequest(GwtRpcController.java:30)
    	at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
    	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875)
    	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:807)
    	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
    	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:511)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    	at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
    	at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
    	at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    	at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
    	at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)
    	at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
    	at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    	at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49)
    	at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    	at org.mortbay.jetty.Server.handle(Server.java:324)
    	at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
    	at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:843)
    	at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:647)
    	at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
    	at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
    	at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
    	at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)
    Caused by: java.lang.NullPointerException

    Pouvez vous m'aider ?

  2. #2
    Membre chevronné
    Profil pro
    Lead Tech Agile
    Inscrit en
    Septembre 2004
    Messages
    316
    Détails du profil
    Informations personnelles :
    Âge : 44
    Localisation : France

    Informations professionnelles :
    Activité : Lead Tech Agile

    Informations forums :
    Inscription : Septembre 2004
    Messages : 316
    Par défaut
    A prioris c'est un problème Spring qui n'a rien à voir avec GWT.

    Le NullPointer est provoqué parce que greetingService est null dans la méthode checkLogin().

    Ce serait donc le Autowired qui ne fonctionne pas.

    Est-ce normal que la ligne suivante contiennent une * ?
    <param-value>classpath*:applicationContext*.xml</param-value>

    Est-ce que la classe GreetingService est bien scanné et a bien l'annotation @Service ?

Discussions similaires

  1. Erreur Java null exception pointer dans un tMap
    Par easynoob dans le forum Développement de jobs
    Réponses: 2
    Dernier message: 12/05/2010, 10h42
  2. Problème de pointer null
    Par carlou135 dans le forum Débuter avec Java
    Réponses: 1
    Dernier message: 05/12/2008, 17h58
  3. [Spring webflow] null _flowId
    Par teryValencia dans le forum Spring Web
    Réponses: 2
    Dernier message: 27/02/2008, 10h07
  4. [JUnit] Pointer null sur objet testé
    Par Mister Nono dans le forum Tests et Performance
    Réponses: 11
    Dernier message: 29/03/2007, 10h38
  5. [tiles][popup]Tile standard --> null exceptions
    Par mezoo dans le forum Struts 1
    Réponses: 3
    Dernier message: 30/11/2006, 14h47

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