Classe @Autowired mais NullPointer à l'utilisation
Bonjour,
J'ai un problème d'instance sur une classe @Autowired.
Dans une classe annotée @Service, je vai appelle à une autre classe qui elle aussi est annotée @Service par le biais @Autowired:
Code:
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
|
@Service
public class ServiceLoad implements IServiceLoad {
@Autowired
private ServiceGet serviceGet;
public String getString(String toto){
return serviceGet.loadString(toto);
}
}
@Service
public class ServiceGet implements IServiceGet {
public String loadString(String toto){
return toto;
}
} |
L'injection spring ce passe bien ca je n'ai pas d'erreur dans les logs, seulement quand je fais appel à mon service ServiceLoad via SoaupUI,
la classe ServiceGet est null, donc je tombe en nullpointer.
Voici mon applicationContext;
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
<!-- Services à découvrir -->
<context:component-scan base-package="fr.toto" />
<!-- Active l'utilisation d'annotations type @Service, @Repository, etc -->
<context:annotation-config/>
<!-- Utilitaire portant le contexte de l'application Spring. -->
<bean class="fr.toto.transverse.ApplicationContextUtils" />
<!-- Initialise log4j -->
<bean id="log4jInitialization"
class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetClass" value="org.springframework.util.Log4jConfigurer" />
<property name="targetMethod" value="initLogging" />
<property name="arguments">
<list>
<value>classpath:\resources\log\log4j.properties</value>
</list>
</property>
</bean> |
ma classe ApplicationContextUtils:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| public class ApplicationContextUtils implements ApplicationContextAware {
/**
* Contexte de l'application Spring.
*/
private static ApplicationContext contexte = null;
/**
* @see com.bea.core.repackaged.springframework.context.ApplicationContextAware#setApplicationContext(com.bea.core.repackaged.springframework.context.ApplicationContext)
*/
public void setApplicationContext(final ApplicationContext applicationContext) throws BeansException {
contexte = applicationContext;
}
/**
* Retourne le contexte de l'application Spring.
*
* @return {@link ApplicationContext}
*/
public static ApplicationContext getApplicationContext() {
return contexte;
}
} |
et mon web.xml utilisé pour un déploiement sous tomcat:
Code:
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 104 105 106 107 108 109 110 111 112 113 114
|
<web-app>
<display-name>Apache-Axis</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:\resources\spring\applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>AxisServlet</servlet-name>
<display-name>Apache-Axis Servlet</display-name>
<!-- <servlet-class>
org.apache.axis.transport.http.AxisServlet
</servlet-class> -->
<servlet-class>
fr.asi.servlet.ContentLengthWsdlAxisServlet
</servlet-class>
</servlet>
<servlet>
<servlet-name>AdminServlet</servlet-name>
<display-name>Axis Admin Servlet</display-name>
<servlet-class>
org.apache.axis.transport.http.AdminServlet
</servlet-class>
<load-on-startup>100</load-on-startup>
</servlet>
<servlet>
<servlet-name>SOAPMonitorService</servlet-name>
<display-name>SOAPMonitorService</display-name>
<servlet-class>
org.apache.axis.monitor.SOAPMonitorService
</servlet-class>
<init-param>
<param-name>SOAPMonitorPort</param-name>
<param-value>5001</param-value>
</init-param>
<load-on-startup>100</load-on-startup>
</servlet>
<servlet>
<servlet-name>ParamServlet</servlet-name>
<display-name>Servlet de parametrage</display-name>
<description>Servlet chargant le parametrage dans les proprietes systeme</description>
<servlet-class>fr.asi.servlet.LoadOnStartupServlet</servlet-class>
<init-param>
<param-name>properties-file</param-name>
<param-value>WEB-INF/sage.properties</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/servlet/AxisServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>*.jws</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>SOAPMonitorService</servlet-name>
<url-pattern>/SOAPMonitor</url-pattern>
</servlet-mapping>
<!-- uncomment this if you want the admin servlet -->
<servlet-mapping>
<servlet-name>AdminServlet</servlet-name>
<url-pattern>/servlet/AdminServlet</url-pattern>
</servlet-mapping>
<!-- currently the W3C havent settled on a media type for WSDL;
http://www.w3.org/TR/2003/WD-wsdl12-20030303/#ietf-draft
for now we go with the basic 'it's XML' response -->
<mime-mapping>
<extension>wsdl</extension>
<mime-type>text/xml</mime-type>
</mime-mapping>
<mime-mapping>
<extension>xsd</extension>
<mime-type>text/xml</mime-type>
</mime-mapping>
<welcome-file-list id="WelcomeFileList">
<welcome-file>index.html</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.jws</welcome-file>
</welcome-file-list>
</web-app> |
Avez vous une solution à mon problème car en test Junit cela fonctionne bien ? Merci D'avance, Damien.