Hello robert.wlaschin,
I followed what you point but now my app do not start.
This is my java class:
Code:
package com.test.services;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import com.mongodb.DB;
import com.mongodb.Mongo;
public class ServiceContextListener implements ServletContextListener {
@Override
public void contextDestroyed(ServletContextEvent context) {
ServletContext sc = context.getServletContext();
WebApplicationContext springContext = WebApplicationContextUtils.getWebApplicationContext(sc);
if (springContext.containsBean("mongoTemplate")) {
MongoTemplate mt = (MongoTemplate) springContext.getBean("mongoTemplate");
if (mt != null) {
DB db = mt.getDb();
if (db != null) {
Mongo mongo = db.getMongo();
if (mongo != null) {
mongo.close();
}
}
}
}
System.gc();
do {
try { // https://jira.mongodb.org/browse/JAVA-400
Thread.sleep(5000);
break;
} catch (InterruptedException e) {
// e.printStackTrace();
}
} while (true);
java.beans.Introspector.flushCaches();
}
@Override
public void contextInitialized(ServletContextEvent arg0) {
}
}
and the lister just after loading the ContextLoaderListener in web.xml
Code:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>com.test.ServiceContextListener</listener-class>
</listener>
I do not get any error in console but I cannot see the welcome page!
I only see 404 not found error
I use Apache Tomcat/7.0.26 with Spring and Spring-data-mongo 3.1.0.RELEASE.
Is there something wrong??
It is critic because my tomcat dies in pre-production environment. How could I tune my server to avoid it?
Thanks at all!