Bonjour,
J'ai posté un message hier au sujet de ce problème sur le forum Spring (http://forum.springframework.org/showthread.php?t=54163). N'ayant eu aucune réponse je viens vous demander un peu d'aide.
Je développe un petit serveur qui expose ses services via RMI. Les services pourront ainsi être appelés à distance.
L'inteface (simplifée) de ce service est la suivante:
L'implémentation du service :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 public interface ServerService { long countAnalysisEngines(); }
countAnalysisEngines() exécute une requête via Hibernate et retourne un nombre.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 @Service("serverService") public class ServerServiceImpl implements ServerService { @Autowired private UimaComponentService uimaComponentService; public long countAnalysisEngines() { return this.uimaComponentService.countAnalysisEngines(); } }
Le test de cette fonction se comporte correctement:
Mon problème intervient lorsque je souhaite exporter ce service via RMI. Ma configuration Spring permettant cette exportation est la 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 ... public class ServerServiceTest { @Autowired @Qualifier("serverService") // @Qualifier("serverServiceClient") private ServerService serverService; @Test public void testCountAnalysisEngines() throws Exception { assertThat(super.serverService.countAnalysisEngines()).isEqualTo(0); ... } }
Pour rendre l'appel à ce service possible sur les clients j'utilise la configuration suivante:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7 <bean class="org.springframework.remoting.rmi.RmiServiceExporter"> <property name="serviceName" value="ServerService" /> <property name="service" ref="serverService" /> <property name="serviceInterface" value="com.thales.imp.secondaryserver.services.ServerService" /> <property name="registryPort" value="1099" /> </bean>
Maintenant je réeffectue mon test sauf que cette fois-ci je n'utilise pas le service "directement" mais j'injecte je proxy RMI (stub):
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 <bean id="serverServiceClient" class="org.springframework.remoting.rmi.RmiProxyFactoryBean"> <property name="serviceUrl" value="rmi://localhost:1099/ServerService" /> <property name="serviceInterface" value="com.thales.imp.secondaryserver.services.ServerService" /> </bean>
A l'exécution de ce test l'erreur suivante apparaît:
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 ... public class ServerServiceTest { @Autowired // @Qualifier("serverService") @Qualifier("serverServiceClient") // Injection du proxy via RmiProxyFactoryBean private ServerService serverService; @Test public void testCountAnalysisEngines() throws Exception { assertThat(super.serverService.countAnalysisEngines()).isEqualTo(0); // Plante ici ... } }
Il semble qu'il y ait un problème avec Hibernate mais je n'arrive pas à comprendre pourquoi !!!
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 2008-05-13 18:54:59,078 (RmiServiceExporter.java:271) - Binding service 'ServerService' to RMI registry: RegistryImpl[UnicastServerRef [liveRef: [endpoint:[139.40.210.19:1099](local),objID:[0:0:0, 0]]]] DEBUG 18:54:59.234 - c.t.i.s.s.i.UimaComponentServiceImpl:114 - Counting Analysis Engines components. DEBUG 18:54:59.250 - c.t.i.s.d.c.h.HbmUimaComponentDao:61 - Counting Analysis Engines components. WARN 2008-05-13 18:54:59,265 (RemoteInvocationTraceInterceptor.java:80) - Processing of RmiServiceExporter remote call resulted in fatal exception: com.thales.imp.secondaryserver.services.ServerServ ice.countAnalysisEngines org.springframework.orm.hibernate3.HibernateSystem Exception: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here; nested exception is org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here at org.springframework.orm.hibernate3.SessionFactoryU tils.convertHibernateAccessException(SessionFactor yUtils.java:661) at org.springframework.orm.hibernate3.AbstractSession FactoryBean.convertHibernateAccessException(Abstra ctSessionFactoryBean.java:303) at org.springframework.orm.hibernate3.AbstractSession FactoryBean.translateExceptionIfPossible(AbstractS essionFactoryBean.java:282) at org.springframework.dao.support.ChainedPersistence ExceptionTranslator.translateExceptionIfPossible(C hainedPersistenceExceptionTranslator.java:62) at org.springframework.dao.support.DataAccessUtils.tr anslateIfNecessary(DataAccessUtils.java:212) at org.springframework.dao.support.PersistenceExcepti onTranslationInterceptor.invoke(PersistenceExcepti onTranslationInterceptor.java:146) at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :171) at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynamicAopProxy.java:204) at $Proxy30.countAnalysisEngines(Unknown Source) at com.thales.imp.secondaryserver.services.impl.UimaC omponentServiceImpl.countAnalysisEngines(UimaCompo nentServiceImpl.java:116) at com.thales.imp.secondaryserver.services.impl.Serve rServiceImpl.countAnalysisEngines(ServerServiceImp l.java:53) at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.springframework.aop.support.AopUtils.invokeJoi npointUsingReflection(AopUtils.java:310) at org.springframework.aop.framework.ReflectiveMethod Invocation.invokeJoinpoint(ReflectiveMethodInvocat ion.java:182) at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :149) at org.springframework.remoting.support.RemoteInvocat ionTraceInterceptor.invoke(RemoteInvocationTraceIn terceptor.java:70) at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :171) at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynamicAopProxy.java:204) at $Proxy33.countAnalysisEngines(Unknown Source) at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.springframework.remoting.support.RemoteInvocat ion.invoke(RemoteInvocation.java:205) at org.springframework.remoting.support.DefaultRemote InvocationExecutor.invoke(DefaultRemoteInvocationE xecutor.java:38) at org.springframework.remoting.support.RemoteInvocat ionBasedExporter.invoke(RemoteInvocationBasedExpor ter.java:78) at org.springframework.remoting.rmi.RmiBasedExporter. invoke(RmiBasedExporter.java:72) at org.springframework.remoting.rmi.RmiInvocationWrap per.invoke(RmiInvocationWrapper.java:72) at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at sun.rmi.server.UnicastServerRef.dispatch(UnicastSe rverRef.java:305) at sun.rmi.transport.Transport$1.run(Transport.java:1 59) at java.security.AccessController.doPrivileged(Native Method) at sun.rmi.transport.Transport.serviceCall(Transport. java:155) at sun.rmi.transport.tcp.TCPTransport.handleMessages( TCPTransport.java:535) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandl er.run0(TCPTransport.java:790) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandl er.run(TCPTransport.java:649) at java.util.concurrent.ThreadPoolExecutor$Worker.run Task(ThreadPoolExecutor.java:885) at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:907) at java.lang.Thread.run(Thread.java:619) Caused by: org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here at org.springframework.orm.hibernate3.SpringSessionCo ntext.currentSession(SpringSessionContext.java:63) at org.hibernate.impl.SessionFactoryImpl.getCurrentSe ssion(SessionFactoryImpl.java:544) at com.thales.imp.server.dao.hbm.AbstractHbmImpDao.cr eateQuery(AbstractHbmImpDao.java:185) at com.thales.imp.secondaryserver.dao.component.hbm.H bmUimaComponentDao.countAnalysisEngines(HbmUimaCom ponentDao.java:63) at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.springframework.aop.support.AopUtils.invokeJoi npointUsingReflection(AopUtils.java:310) at org.springframework.aop.framework.ReflectiveMethod Invocation.invokeJoinpoint(ReflectiveMethodInvocat ion.java:182) at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :149) at org.springframework.dao.support.PersistenceExcepti onTranslationInterceptor.invoke(PersistenceExcepti onTranslationInterceptor.java:138) ... 39 more
Peut-être que ceci vient du fait que lorsque j'utilise le proxy RMI le code client ne s'exécute pas dans le même Thread que le code serveur (le code du service exporté) ???
Comment résoudre ce problème ???
Merci.
Partager