1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.struts2.spring;
22
23 import org.springframework.beans.factory.support.SimpleInstantiationStrategy;
24 import org.springframework.beans.factory.support.RootBeanDefinition;
25 import org.springframework.beans.factory.BeanFactory;
26 import org.springframework.beans.BeanInstantiationException;
27 import org.springframework.beans.BeanUtils;
28
29 import java.lang.reflect.Constructor;
30
31 /***
32 * Same as SimpleInstantiationStrategy, but constructor is not cached
33 */
34 public class ClassReloadingInstantiationStrategy extends SimpleInstantiationStrategy {
35 public Object instantiate(
36 RootBeanDefinition beanDefinition, String beanName, BeanFactory owner) {
37
38
39 if (beanDefinition.getMethodOverrides().isEmpty()) {
40 Class clazz = beanDefinition.getBeanClass();
41 if (clazz.isInterface()) {
42 throw new BeanInstantiationException(clazz, "Specified class is an interface");
43 }
44 try {
45 Constructor constructor = clazz.getDeclaredConstructor((Class[]) null);
46 return BeanUtils.instantiateClass(constructor, null);
47 }
48 catch (Exception ex) {
49 throw new BeanInstantiationException(clazz, "No default constructor found", ex);
50 }
51 } else {
52
53 return instantiateWithMethodInjection(beanDefinition, beanName, owner);
54 }
55 }
56 }