Struts2中Action的创建
还是先贴出在Struts2里面创建Action的地方:
protected void createAction(Map<String, Object> contextMap) {
// load action
String timerKey = "actionCreate: " + proxy.getActionName();
try {
UtilTimerStack.push(timerKey);
action = objectFactory.buildAction(proxy.getActionName(), proxy.getNamespace(), proxy.getConfig(), contextMap);
大家可以看到这个action是由objectFactory来创建的,那么我们继续跟踪,进入上面的buildAction看看怎么写的:如下
public Object buildAction(String actionName,
String namespace, ActionConfig config, Map<String, Object>
extraContext) throws Exception {
return buildBean(config.getClassName(), extraContext);
}
可以看出来他是调用了buildBean方法,没关系,我们继续跟踪buildBean方法,如下
public Object buildAction(String actionName,
String namespace, ActionConfig config, Map<String, Object>
extraContext) throws Exception {
return buildBean(config.getClassName(), extraContext);
}