package com.smtservlet.core; import java.io.File; import java.net.URL; import java.net.URLClassLoader; import javax.servlet.ServletContext; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.web.context.support.XmlWebApplicationContext; public class SMTWebApplicationContext extends XmlWebApplicationContext { public static class SMTContextClassLoader extends URLClassLoader { public SMTContextClassLoader(ClassLoader parentClassLoader) { super(new URL[0], parentClassLoader); } public void addJarFile(File file) throws Exception { this.addURL(file.toURI().toURL()); } } SMTContextClassLoader classLoader = null; public SMTWebApplicationContext() throws Exception { super(); } public void setServletContext(ServletContext servletContext) { super.setServletContext(servletContext); // String jsonFileName = servletContext.getInitParameter("contextClassJson"); // // if(!SMTStatic.isNullOrEmpty(jsonFileName)) // { // String webRootPath = servletContext.getRealPath("/"); // File fileJson = new File(jsonFileName.replace("{WEB-ROOT}", webRootPath)); // Json jsonPlugin = Json.read(fileJson); // classLoader = new SMTContextClassLoader(super.getClassLoader()); // try { // classLoader.addJarFile(new File("D:/TEST_PROJECT/test_classloader/test_jar1.jar")); // } catch (Exception e) { // // e.printStackTrace(); // } // } } @Override public ClassLoader getClassLoader() { return classLoader != null ? classLoader : super.getClassLoader(); } @Override protected void finishBeanFactoryInitialization(ConfigurableListableBeanFactory beanFactory) { super.finishBeanFactoryInitialization(beanFactory); } }