|
Struts example source code file (ClassReloadingXMLWebApplicationContext.java)
The Struts ClassReloadingXMLWebApplicationContext.java source code/* * $Id: ClassReloadingXMLWebApplicationContext.java 1076544 2011-03-03 07:19:37Z lukaszlenart $ * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package org.apache.struts2.spring; import com.opensymphony.xwork2.util.classloader.FileResourceStore; import com.opensymphony.xwork2.util.classloader.JarResourceStore; import com.opensymphony.xwork2.util.classloader.ReloadingClassLoader; import com.opensymphony.xwork2.util.logging.Logger; import com.opensymphony.xwork2.util.logging.LoggerFactory; import org.apache.commons.jci.monitor.FilesystemAlterationListener; import org.apache.commons.jci.monitor.FilesystemAlterationMonitor; import org.apache.commons.jci.monitor.FilesystemAlterationObserver; import org.apache.commons.lang.StringUtils; import org.apache.struts2.dispatcher.Dispatcher; import org.springframework.web.context.support.XmlWebApplicationContext; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.BeansException; import javax.servlet.ServletContext; import java.io.File; import java.util.List; import java.util.ArrayList; import java.util.Set; import java.util.HashSet; import java.util.regex.Pattern; /** * This class can be used instead of XmlWebApplicationContext, and it will watch jar files and directories for changes * and reload then changed classes. * <br /> * To use this class: * <ul> * <li>Set "struts.devMode" to "true" * <li>Set "struts.class.reloading.watchList" to a comma separated list of directories, or jar files (absolute paths) * <li>Add this to web.xml: * <pre> * <context-param> * <param-name>contextClass</param-name> * <param-value>org.apache.struts2.spring.ClassReloadingXMLWebApplicationContext</param-value> * </context-param> * </li> * <li>Add Apache Commons JCI FAM to the classpath. If you are using maven, add this to pom.xml: * <pre> * <dependency> * <groupId>org.apache.commons</groupId> * <artifactId>commons-jci-fam</artifactId> * <version>1.0</version> * <optional>true</optional> * </dependency> * </pre> * </li> * </ul> */ public class ClassReloadingXMLWebApplicationContext extends XmlWebApplicationContext implements FilesystemAlterationListener { private static final Logger LOG = LoggerFactory.getLogger(ClassReloadingXMLWebApplicationContext.class); protected ReloadingClassLoader classLoader; protected FilesystemAlterationMonitor fam; protected ClassReloadingBeanFactory beanFactory; //reload the runtime configuration when a change is detected private boolean reloadConfig; public void setupReloading(String[] watchList, String acceptClasses, ServletContext servletContext, boolean reloadConfig) { this.reloadConfig = reloadConfig; classLoader = new ReloadingClassLoader(ClassReloadingXMLWebApplicationContext.class.getClassLoader()); //make a list of accepted classes if (StringUtils.isNotBlank(acceptClasses)) { String[] splitted = acceptClasses.split(","); Set<Pattern> patterns = new HashSet Other Struts examples (source code examples)Here is a short list of links related to this Struts ClassReloadingXMLWebApplicationContext.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.