Aop拦截到的Action 使得@Autowired 无法自动装配问题解决 (四)

2014-11-24 11:54:49 · 作者: · 浏览: 79
tring *()) && !execution(public String toString())" + " && target(code.coolbaby.core.CRUDActionSupport)")
void timer() {
}

@Around("timer()")
public Object time(ProceedingJoinPoint joinPoint) throws Throwable {

String clazz = joinPoint.getTarget().getClass().getSimpleName();
String method = joinPoint.getSignature().getName();

StopWatch clock = new StopWatch();
clock.start();
Object result = joinPoint.proceed();
clock.stop();

String[] params = new String[] { clazz, method, clock.getTime() + "" };
logger.info("[{}]执行[{}]方法共消耗[{}]毫秒", params);

return result;
}

}
struts.xml内容如下:
[xml]
< xml version="1.0" encoding="UTF-8" >
"http://struts.apache.org/dtds/struts-2.1.dtd">











AUTOMATIC









< xml version="1.0" encoding="UTF-8" >
"http://struts.apache.org/dtds/struts-2.1.dtd">











AUTOMATIC






在applicationcontext.xml加入以下配置:
[xml]



理论上讲,AOP的功能应该可以正确实现了,实际则不然,以UserAction举例说明,
[java]
package code.coolbaby.basal.web.security;

//限于篇幅,省略import语句

/**
* 用户管理Action.
*
* 使用Struts2 convention-plugin Annotation定义Action参数.
*
* @author Kanine
*/
@SuppressWarnings("serial")
public class UserAction extends CRUDActionSupport {

@Autowired
private UserManager userManager;

private User entity;
private Long id;
private Page page = new Page(5);//每页5条记录

public User getModel() {
return entity;
}

@Override
protected void prepareModel() throws Exception {
if (id != null) {
entity = userManager.get(id);
} else {
entity = new User();
}
}

public void setId(Long id) {
this.id = id;
}

public Page getPage() {
return page;
}

@Override
public String list() throws Exception {
HttpServletRequest request = Struts2Utils.getRequest();
List filters = HibernateWebUtils.buildPropertyFilters(request);

page = userManager.search(page, filters);
return SUCCESS;
}
//限于篇幅,省略其他的代码
}

package code.coolbaby.basal.web.security;

//限于篇幅,省略import语句

/**
* 用户管理Action.
*
* 使用Struts2 convention-plugin Annotation定义Action参数.
*
* @author Kanine
*/
@SuppressWarnings("serial")
public class UserAction extends CRUDActionSupport {

@Autowired
private UserManager userManager;

private User entity;
private Long id;
private Page page = new Page(5);//每页5条记录

public User getModel() {
return entity;
}

@Override
protected void prepareModel() throws Exception {
if (id != null) {
entity = userManager.get(id);
} else {
entity = new User();
}
}

public void setId(Long id) {
this.id = id;
}

public Page getPage() {
return page;
}

@Override
public String list() throws Exception {
HttpServletRequest request = Struts2Utils.getRequest();
List filters = HibernateWebUtils.buildPropertyFilters(request);

page = userManager.search(page, filt