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 ?