[Tomcat 7/SpringMVC] Memory Leak inévitable ?
Bonjour,
J'ai décidé de découvrir Spring (mvc, security, ...).
J'utilise Netbeans 7.4, Tomcat 7.0.42 et Spring (spring-context 3.2.4 et spring-web 3.2.0)
Au bout d'un temps, je me suis aperçu que tomcat arrivé au bout sa mémoire, le fameux : "java.lang.OutOfMemoryError: PermGen space" :cry:.
Pour isolé au mieux la source de mon problème, je suis repartir sur un projet de zéro et j'ai repris des morceaux de code et au final j'en suis arrivé à n'utiliser que SpringMVC.
Lorsque je redeploy ma simple appli SpringMVC, Tomcat me détecte une fuite mémoire (le bouton "Find leak"). Je n'en trouve pas la cause (ou du moins du mal à croire que ça soit Spring ...).
Afin de réduire ma fuite mémoire j'en suis arrivé à coller spring directement dans le dossier lib de tomcat :pastaper:
Voici les dépendances du pom.xml :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.2.4.RELEASE</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.2.0.RELEASE</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency> |
Voici mon web.xml :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| <?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<servlet>
<servlet-name>SpringServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>SpringServlet</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app> |
Voici l'applicationContext.xml :
Code:
1 2 3 4 5 6 7 8 9 10 11 12
| <?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: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/context http://www.springframework.org/schema/context/spring-context.xsd
">
<context:component-scan base-package="com.memoryleak" />
</beans> |
Et Voici mon contrôleur de test :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| /*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.memoryleak;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class Login {
@RequestMapping(value = "/test", method = RequestMethod.GET)
public void test() {
}
} |
Je trouve l'appli de tes assez simple mais pourtant impossible de trouver la fuite mémoire.
Ai-je fais une erreur de config ?
Est-il impossible d'utilise Spring sans fuite mémoire ?
Cela fait un moment que je cherche en vain.
En attendant, merci d'avance :)