为什么 Spring 不将映射注入到子 Struts 2 Action 类中,而是注入父对象的对象?
我在 Spring applicationContext.xml 中有以下配置,以便将对象注入到我的 Struts 2 Java 项目中:
<util:map id="typeToURLMap">
<entry key="TYPEA" value="./ur1.x" />
<entry key="TYPEB" value="./url2.x" />
<entry key="TYPEC" value="./url3.x" />
<entry key="OTHER" value="./url4.x" />
</util:map>
<bean id="parentAction" class="my.package.ParentAction" scope="prototype">
<property name="businessDelegate" ref="businessDelegateNotRelevantToThisExample" />
</bean>
<bean id="childAction" class="my.package.ChildAction" scope="prototype" parent="parentAction">
<property name="typeToURLMap" ref="typeToURLMap"/>
</bean>
由于某种原因,在父 Action 上调用 setter,但在子 Action 中不调用 setter。 这个配置有什么问题吗?
注意:据我了解,util:map 将默认为 Java 类型的 HashMap。
我的 ParentAction 如下所示:
public class ParentAction extends MyAppBaseAction {
private BusinessDelegate businessDelegate;
//other action code using business delegate
/**
* This IS called.
*/
public void setBusinessDelegate(BusinessDelegate delegate){
this.businessDelegate = delegate;
}
}
我的 ChildAction 如下所示:
public class ChildAction extends ParentAction{
private Map<String,String> typeToURLMap;
//other action code using map
/**
* Never Called! (Why?)
*/
public void setTypeToURLMap(Map<String,String map){
this.typeToURLMap = map;
}
}
任何帮助将不胜感激。谢谢!
I have the following configuration in my Spring applicationContext.xml in order to inject objects into my Struts 2 Java project:
<util:map id="typeToURLMap">
<entry key="TYPEA" value="./ur1.x" />
<entry key="TYPEB" value="./url2.x" />
<entry key="TYPEC" value="./url3.x" />
<entry key="OTHER" value="./url4.x" />
</util:map>
<bean id="parentAction" class="my.package.ParentAction" scope="prototype">
<property name="businessDelegate" ref="businessDelegateNotRelevantToThisExample" />
</bean>
<bean id="childAction" class="my.package.ChildAction" scope="prototype" parent="parentAction">
<property name="typeToURLMap" ref="typeToURLMap"/>
</bean>
For some reason, the setter is being called on the parent Action, but not in the child Action. Is there anything wrong with this configuration?
Note: It is my understanding that util:map will default to a Java type of HashMap.
My ParentAction looks like the following:
public class ParentAction extends MyAppBaseAction {
private BusinessDelegate businessDelegate;
//other action code using business delegate
/**
* This IS called.
*/
public void setBusinessDelegate(BusinessDelegate delegate){
this.businessDelegate = delegate;
}
}
My ChildAction looks like the following:
public class ChildAction extends ParentAction{
private Map<String,String> typeToURLMap;
//other action code using map
/**
* Never Called! (Why?)
*/
public void setTypeToURLMap(Map<String,String map){
this.typeToURLMap = map;
}
}
Any help would be greatly appreciated. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试为applicationContext.xml文件编写单元测试
如果测试通过然后看看struts是如何与spring集成的
Try writing a unit test for the applicationContext.xml file
If the test passes then look at how struts is integrated with spring