Author: musachy
Date: Sun Jul 12 18:17:55 2009
New Revision: 793388
URL: http://svn.apache.org/viewvc?rev=793388&view=rev
Log:
WW-3183 Add class reloading to the Spring plugin
Added:
struts/struts2/trunk/plugins/spring/src/main/java/org/apache/struts2/spring/ClassReloadingBeanFactory.java
(with props)
struts/struts2/trunk/plugins/spring/src/main/java/org/apache/struts2/spring/ClassReloadingInstantiationStrategy.java
(with props)
struts/struts2/trunk/plugins/spring/src/main/java/org/apache/struts2/spring/ClassReloadingXMLWebApplicationContext.java
(with props)
Modified:
struts/struts2/trunk/plugins/spring/pom.xml
struts/struts2/trunk/plugins/spring/src/main/java/org/apache/struts2/spring/StrutsSpringObjectFactory.java
struts/struts2/trunk/plugins/spring/src/test/java/org/apache/struts2/spring/StrutsSpringObjectFactoryTest.java
Modified: struts/struts2/trunk/plugins/spring/pom.xml
URL:
http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/spring/pom.xml?rev=793388&r1=793387&r2=793388&view=diff
==
--- struts/struts2/trunk/plugins/spring/pom.xml (original)
+++ struts/struts2/trunk/plugins/spring/pom.xml Sun Jul 12 18:17:55 2009
@@ -72,6 +72,13 @@
+org.apache.commons
+commons-jci-fam
+1.0
+true
+
+
+
junit
junit
test
Added:
struts/struts2/trunk/plugins/spring/src/main/java/org/apache/struts2/spring/ClassReloadingBeanFactory.java
URL:
http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/spring/src/main/java/org/apache/struts2/spring/ClassReloadingBeanFactory.java?rev=793388&view=auto
==
---
struts/struts2/trunk/plugins/spring/src/main/java/org/apache/struts2/spring/ClassReloadingBeanFactory.java
(added)
+++
struts/struts2/trunk/plugins/spring/src/main/java/org/apache/struts2/spring/ClassReloadingBeanFactory.java
Sun Jul 12 18:17:55 2009
@@ -0,0 +1,96 @@
+/*
+ * $Id$
+ *
+ * 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 org.springframework.beans.BeanWrapper;
+import org.springframework.beans.factory.support.RootBeanDefinition;
+import org.springframework.beans.factory.support.DefaultListableBeanFactory;
+import org.springframework.beans.factory.CannotLoadBeanClassException;
+import org.springframework.util.ObjectUtils;
+import org.springframework.util.ClassUtils;
+import org.springframework.core.DecoratingClassLoader;
+
+import java.lang.reflect.Constructor;
+
+
+/**
+ * Same as DefaultListableBeanFactory, but it doesn't use the constructor and
class cached in RootBeanDefinition
+ */
+public class ClassReloadingBeanFactory extends DefaultListableBeanFactory {
+@Override
+protected BeanWrapper createBeanInstance(String beanName,
RootBeanDefinition mbd, Object[] args) {
+Class beanClass = resolveBeanClass(mbd, beanName);
+
+if (mbd.getFactoryMethodName() != null) {
+return instantiateUsingFactoryMethod(beanName, mbd, args);
+}
+
+//commented to cached constructor is not used
+/* // Shortcut when re-creating the same bean...
+if (mbd.resolvedConstructorOrFactoryMethod != null) {
+if (mbd.constructorArgumentsResolved) {
+return autowireConstructor(beanName, mbd, null, args);
+} else {
+return instantiateBean(beanName, mbd);
+}
+}*/
+
+// Need to determine the constructor...
+Constructor[] ctors =
determineConstructorsFromBeanPostProcessors(beanClass, beanName);
+if (ctors != null ||
+mbd.getResolvedAutowireMode() ==
RootBeanDefinition.AUTOWIRE_CONSTRUCTOR ||
+mbd.hasConstructorArgumentValues() ||
!ObjectUtils.isEmpty(args)) {
+return autowireConstructor(beanName, mbd, ctors, args);
+}
+
+// No special handling: simply use no-arg constructor.
+return instantiateBean(beanName, mbd);
+}
+
+protected Class resolveBeanClass(RootBeanDefinition mbd,