Bonjour,
Je suis en train de créer des services web avec Axis sur une base de Spring/Hibernate.
Mon probleme est qu'a chaque appel de mon service web, je me retrouve avec une nouvelle connexion à la base de donnée qui ne se ferme jamais...
Est-ce un probleme de réglage ou bien une erreur de code?
Voici mon beans.xml:
J'ai donc paramétré un pool de connexions de 5 si j'ai bien compris, cependant je les dépasses largement dans le cas suivant:
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 <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:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd "> <tx:annotation-driven /> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="org.postgresql.Driver" /> <property name="url" value="jdbc:postgresql://monserveur/mabase" /> <property name="username" value="utilisateur" /> <property name="password" value="mdp" /> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="annotatedClasses"> <list> ... liste de mes classes annotées pour hibernate </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop> <prop key="hibernate.show_sql">false</prop> <prop key="hibernate.hbm2ddl.auto">update</prop> <prop key="hibernate.connection.pool_size">5</prop> </props> </property> </bean> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <context:component-scan base-package="org.toto"/> </beans>
Si j'appelle mon application contexte ainsi:
En revanche je ne prend qu'une unique connexion si j'appelle mon application context ainsi:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6 public class Utility { public static synchronized ApplicationContext getAContext() { return new ClassPathXmlApplicationContext("beans.xml"); } }
Ma question: mon parametrage de beans.xml est-il bon? Faut-il appeler le application context de maniere unique ou à chaque appel d'un service web, faut il en faire un new?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8 public class Utility { private static ApplicationContext ac=null; public static synchronized ApplicationContext getAContext() { if(ac==null){ac= new ClassPathXmlApplicationContext("beans.xml");} return ac; } }
Bien Cordialement
Kaoualeo
Partager