diff --git a/core/src/main/java/org/apache/struts2/factory/PrefixBasedActionProxyFactory.java b/core/src/main/java/org/apache/struts2/factory/PrefixBasedActionProxyFactory.java index 03052ec6a..cf196a9b2 100644 --- a/core/src/main/java/org/apache/struts2/factory/PrefixBasedActionProxyFactory.java +++ b/core/src/main/java/org/apache/struts2/factory/PrefixBasedActionProxyFactory.java @@ -59,12 +59,11 @@ import java.util.Set; * * */ -public class PrefixBasedActionProxyFactory extends StrutsActionProxyFactory implements Initializable { +public class PrefixBasedActionProxyFactory extends StrutsActionProxyFactory { private static final Logger LOG = LogManager.getLogger(PrefixBasedActionProxyFactory.class); private Map actionProxyFactories = new HashMap<>(); - private Set prefixes = new HashSet<>(); @Inject public void setContainer(Container container) { @@ -74,22 +73,18 @@ public class PrefixBasedActionProxyFactory extends StrutsActionProxyFactory impl @Inject(StrutsConstants.PREFIX_BASED_MAPPER_CONFIGURATION) public void setPrefixBasedActionProxyFactories(String list) { if (list != null) { - prefixes = new HashSet<>(Arrays.asList(list.split(","))); - } - } - - @Override - public void init() { - for (String factory : prefixes) { - String[] thisFactory = factory.split(":"); - if (thisFactory.length == 2) { - String factoryPrefix = thisFactory[0].trim(); - String factoryName = thisFactory[1].trim(); - ActionProxyFactory obj = container.getInstance(ActionProxyFactory.class, factoryName); - if (obj != null) { - actionProxyFactories.put(factoryPrefix, obj); - } else { - LOG.warn("Invalid PrefixBasedActionProxyFactory config entry: [{}]", factory); + Set prefixes = new HashSet<>(Arrays.asList(list.split(","))); + for (String factory : prefixes) { + String[] thisFactory = factory.split(":"); + if (thisFactory.length == 2) { + String factoryPrefix = thisFactory[0].trim(); + String factoryName = thisFactory[1].trim(); + ActionProxyFactory obj = container.getInstance(ActionProxyFactory.class, factoryName); + if (obj != null) { + actionProxyFactories.put(factoryPrefix, obj); + } else { + LOG.warn("Invalid PrefixBasedActionProxyFactory config entry: [{}]", factory); + } } } } diff --git a/core/src/test/java/org/apache/struts2/factory/PrefixBasedActionProxyFactoryTest.java b/core/src/test/java/org/apache/struts2/factory/PrefixBasedActionProxyFactoryTest.java index 827b86b7d..f19c184ab 100644 --- a/core/src/test/java/org/apache/struts2/factory/PrefixBasedActionProxyFactoryTest.java +++ b/core/src/test/java/org/apache/struts2/factory/PrefixBasedActionProxyFactoryTest.java @@ -23,7 +23,7 @@ public class PrefixBasedActionProxyFactoryTest extends StrutsInternalTestCase { private PrefixBasedActionProxyFactory factory; public void testDifferentPrefixes() throws Exception { - initFactory("/ns1:prefix1,/ns2:prefix2"); + factory.setPrefixBasedActionProxyFactories("/ns1:prefix1,/ns2:prefix2"); ActionProxy proxy1 = factory.createActionProxy("/ns1", "", "", Collections.emptyMap(), false, true); assertTrue(proxy1 instanceof Prefix1ActionProxy); @@ -33,7 +33,7 @@ public class PrefixBasedActionProxyFactoryTest extends StrutsInternalTestCase { } public void testFallbackToDefault() throws Exception { - initFactory("/ns1:prefix1"); + factory.setPrefixBasedActionProxyFactories("/ns1:prefix1"); ActionProxy proxy1 = factory.createActionProxy("/ns1", "", "", Collections.emptyMap(), false, true); assertTrue(proxy1 instanceof Prefix1ActionProxy); @@ -43,7 +43,7 @@ public class PrefixBasedActionProxyFactoryTest extends StrutsInternalTestCase { } public void testEmptyPrefix() throws Exception { - initFactory(":prefix1"); + factory.setPrefixBasedActionProxyFactories(":prefix1"); ActionProxy proxy1 = factory.createActionProxy("/ns1", "", "", Collections.emptyMap(), false, true); assertTrue(proxy1 instanceof Prefix1ActionProxy); @@ -86,9 +86,10 @@ public class PrefixBasedActionProxyFactoryTest extends StrutsInternalTestCase { factory.setContainer(container); } - void initFactory(String prefixes) { - factory.setPrefixBasedActionProxyFactories(prefixes); - factory.init(); + @Override + public void tearDown() throws Exception { + super.tearDown(); + factory = null; } public static class Prefix1Factory extends DefaultActionProxyFactory {