Bonjour,
Je développe des web services avec spring 2.5. et J'ai l'erreur suivante en déployant l'application :
Je pense que le problème est dans les annotations, mais je ne sais pas comment le résoudre
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 INFO: Initializing Spring root WebApplicationContext log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader). log4j:WARN Please initialize the log4j system properly. 4 juin 2012 17:06:06 org.apache.catalina.core.StandardContext listenerStart GRAVE: Exception lors de l'envoi de l'évènement contexte initialisé (context initialized) à l'instance de classe d'écoute (listener) org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'MeteoPrevisionEndpoint' defined in class path resource [applicationContext-ws.xml]: Cannot resolve reference to bean 'MeteoServiceImpl' while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'MeteoServiceImpl' is defined at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:275) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:104) at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:495) at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:162) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:925) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:835) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:440) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409) at java.security.AccessController.doPrivileged(Native Method) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380) at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4206) at org.apache.catalina.core.StandardContext.start(StandardContext.java:4705) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057) at org.apache.catalina.core.StandardHost.start(StandardHost.java:840) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057) at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463) at org.apache.catalina.core.StandardService.start(StandardService.java:525) at org.apache.catalina.core.StandardServer.start(StandardServer.java:754) at org.apache.catalina.startup.Catalina.start(Catalina.java:595) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414) Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'MeteoServiceImpl' is defined at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:387) at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:971) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:246) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:269) ... 35 more 4 juin 2012 17:06:06 org.apache.catalina.core.StandardContext start GRAVE: Error listenerStart 4 juin 2012 17:06:06 org.apache.catalina.core.StandardContext start GRAVE: Erreur de démarrage du contexte [/Contenu20] suite aux erreurs précédentes 4 juin 2012 17:06:06 org.apache.catalina.core.ApplicationContext log INFO: Closing Spring root WebApplicationContext 4 juin 2012 17:06:06 org.apache.coyote.http11.Http11Protocol start INFO: Démarrage de Coyote HTTP/1.1 sur http-8080 4 juin 2012 17:06:07 org.apache.jk.common.ChannelSocket init INFO: JK: ajp13 listening on /0.0.0.0:8009 4 juin 2012 17:06:07 org.apache.jk.server.JkMain start INFO: Jk running ID=0 time=0/188 config=null 4 juin 2012 17:06:07 org.apache.catalina.startup.Catalina start INFO: Server startup in 10287 ms
Voici le code:
applicationContext-ws.xml
MeteoService.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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143 <?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:oxm="http://www.springframework.org/schema/oxm" xmlns:sws="http://www.springframework.org/schema/web-services" 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/oxm http://www.springframework.org/schema/oxm/spring-oxm-1.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/web-services http://www.springframework.org/schema/web-services/web-services-1.5.xsd"> <context:component-scan base-package="com.tunisiana.sample.services" /> <!-- ===================== SOAP ===================================== --> <bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory" /> <bean id="messageReceiver" class="org.springframework.ws.soap.server.SoapMessageDispatcher" /> <!-- ===================== ENDPOINTS ===================================== --> <!-- <bean id="MeteoServiceImpl" class="com.sample.service.Impl.MeteoServiceImpl"> </bean> --> <bean id="MeteoPrevisionEndpoint" class="com.tunisiana.sample.ws.MeteoPrevisionEndpoint"> <constructor-arg ref="MeteoServiceImpl" /> <constructor-arg ref="marshaller" /> </bean> <oxm:jaxb2-marshaller id="marshaller" contextPath="com.sample.schema" /> <!-- ===================== ENDPOINT MAPPINGS ============================== --> <bean id="annotationMapping" class="org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping"> <property name="interceptors"> <list> <bean class="org.springframework.ws.server.endpoint.interceptor.PayloadLoggingInterceptor" /> <bean class="org.springframework.ws.soap.server.endpoint.interceptor.PayloadValidatingInterceptor"> <property name="xsdSchema" ref="schema" /> <property name="validateRequest" value="true" /> <property name="validateResponse" value="false" /> </bean> </list> </property> <property name="order" value="1" /> </bean> <bean id="schema" class="org.springframework.xml.xsd.SimpleXsdSchema"> <property name="xsd" value="/messages.xsd" /> </bean> <!-- ===================== ENDPOINT ADAPTERS ============================== --> <sws:xpath-endpoints> <sws:namespace prefix="messages" uri="http://www.tunisiana.com/samples/meteo/schemas/messages"/> </sws:xpath-endpoints> <!-- ===================== ENDPOINT EXCEPTION RESOLVER ===================== --> <bean class="org.springframework.ws.soap.server.endpoint.SoapFaultMappingExceptionResolver"> <description> This exception resolver maps other exceptions to SOAP Faults. Both UnmarshallingException and ValidationFailureException are mapped to a SOAP Fault with a "Client" fault code. All other exceptions are mapped to a "Server" error code, the default. </description> <property name="defaultFault" value="SERVER"/> <property name="exceptionMappings"> <props> <prop key="org.springframework.oxm.UnmarshallingFailureException">CLIENT,Invalid request</prop> <prop key="org.springframework.oxm.ValidationFailureException">CLIENT,Invalid request</prop> </props> </property> <property name="order" value="2"/> </bean> </beans>
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 public interface MeteoService { List<Meteo> getMeteoJour(String date_jour); List<Meteo> getMeteoPrevision(String date_jour,VilleClass ville); }
MeteoServiceImpl.java
MeteoPrevisionEndpoint.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
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 @Service("MeteoServiceImpl") @Transactional public class MeteoServiceImpl implements MeteoService { @Override @Transactional(readOnly = true) public List<Meteo> getMeteoPrevision(String date_jour,VilleClass ville) { List<Meteo> previsions = new ArrayList<Meteo>(); Meteo meteoprevision=new Meteo(); meteoprevision.setVille(ville); DatatypeFactory factory; try { factory = DatatypeFactory.newInstance(); } catch (DatatypeConfigurationException e) { throw new RuntimeException("DatatypeConfigurationException",e); } //meteoprevision.setDate(factory.newXMLGregorianCalendar(new GregorianCalendar())); meteoprevision.setTemp("20°"); meteoprevision.setTempmin("18°"); meteoprevision.setTempmax("23°"); meteoprevision.setIcone("ensoleillé"); previsions.add(meteoprevision); return previsions; } @Override @Transactional(readOnly = true) public List<Meteo> getMeteoJour(String date_jour) { List<Meteo> meteo_villes = new ArrayList<Meteo>(); Meteo meteojour=new Meteo(); meteojour.setVille(VilleClass.TUNIS); DatatypeFactory factory; try { factory = DatatypeFactory.newInstance(); } catch (DatatypeConfigurationException e) { throw new RuntimeException("DatatypeConfigurationException",e); } XMLGregorianCalendar date = factory.newXMLGregorianCalendar(new GregorianCalendar()); //meteojour.setDate(date); meteojour.setTemp("20°"); meteojour.setTempmin("18°"); meteojour.setTempmax("22°"); meteojour.setPression("10 bar"); meteojour.setHumidite("60%"); meteojour.setVisibilite("???"); meteojour.setIcone("ensoleillé"); meteojour.setVitesseVent("10 km/h"); meteojour.setDirVent("Est"); meteojour.setSensVent("Est"); /*meteojour.setLeveeSoleil(value); meteojour.setPointRosee(value); meteojour.setPriereFajr(value); meteojour.setPriereDhohr(value); meteojour.setPriereAsr(value); meteojour.setPriereMaghrib(value); meteojour.setPriereIsha(value);*/ meteo_villes.add(meteojour); return meteo_villes; } }
Si je remplace la déclaration du service MeteoServiceImpl utilisant les annotations par une déclaration explicite dans le fichier de config applicationContext-ws.xml, tout marche bien:
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 @Endpoint public class MeteoPrevisionEndpoint { private static final Log logger = LogFactory.getLog(MeteoPrevisionEndpoint.class); private ObjectFactory objectFactory = new ObjectFactory(); private MeteoService meteoService; private Marshaller marshaller; public MeteoPrevisionEndpoint(MeteoService meteoService, Marshaller marshaller) { this.meteoService = meteoService; this.marshaller = marshaller; } @PayloadRoot(localPart = "GetMeteoPrevisionRequest", namespace = "http://www.tunisiana.com/samples/meteo/schemas/messages") public Source getMeteoPrevision(@XPathParam("//messages:date_jour")String date_jourString, @XPathParam("//messages:villeClass")String villeClassString) { if (logger.isDebugEnabled()) { logger.debug("Received GetMeteoPrevisionRequest '" + villeClassString + "' ville "+ date_jourString); } // 1- récupérer les données de la requête et les ajuster VilleClass villeClass = null; if (StringUtils.hasLength(villeClassString)) { villeClass = VilleClass.fromValue(villeClassString); } List<Meteo> meteoprevisions = meteoService.getMeteoPrevision(date_jourString,villeClass); GetMeteoPrevisionResponse response= objectFactory.createGetMeteoPrevisionResponse(); for (Meteo domainMeteoPrevision : meteoprevisions) { response.getMeteo().add(domainMeteoPrevision); } return new MarshallingSource(marshaller, response); } }
mais je voulais utliser les annotations. Est ce qu'il s'agit d'un problème de jar manquant??
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3 <bean id="MeteoServiceImpl" class="com.sample.service.Impl.MeteoServiceImpl"> </bean>
Quelqu'un peut m'aider s'il vous plait?
Partager