如果我激活了Aspect,那么所有的映射似乎都被禁用了:
这是我的抽象控制器:DEBUG: org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - 未找到[/contact/2]的处理程序方法
WARN : org.springframework.web.servlet.PageNotFound - 没有映射HTTP请求URI为[/clubhelperbackend/contact/2] 的调度Servlet名称'appServlet'
public abstract class AbstractController<T extends Data> implements ClubController<T> {
protected Dao<T> dao;
private Class<T> elementClass;
public AbstractController(Dao<T> dao, Class<T> element) {
super();
this.dao = dao;
this.elementClass = element;
}
@Override
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public String getAsView(@PathVariable("id") long id, @RequestParam(required = false) boolean ajax, Model m) {
String mapping = elementClass.getSimpleName();
m.addAttribute(mapping, getById(id));
return mapping + "Get" + (ajax ? "Ajax" : "");
}
@Override
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE, produces = "application/json")
public T delete(@PathVariable("id") long id) {
T obj = getById(id);
// dao.delete(id);
return obj;
}
}
一个实现:
@Controller
@RequestMapping("/contact")
public class ContactController extends AbstractController<Contact> {
@Autowired
public ContactController(Dao<Contact> contactDao) {
super(contactDao, Contact.class);
}
}
这是我的切面(Aspect):
@Aspect
@Component
public class DeletedStorageAspect {
//
// private DeletedEntriesDao deletedEntriesDao;
//
// @Autowired
// public DeletedStorageAspect(DeletedEntriesDao deletedEntriesDao) {
// super();
// this.deletedEntriesDao = deletedEntriesDao;
// }
@Pointcut("execution (public * de.kreth.clubhelperbackend.controller.abstr.AbstractController.delete(..))")
private void invocation() {
}
@AfterReturning(pointcut = "invocation()", returning = "deleted")
public void storeDeleted(JoinPoint joinPoint, Data deleted) {
System.out.println("Deleted: " + deleted);
String tableName = deleted.getClass().getSimpleName();
long id = deleted.getId();
Date now = new Date();
DeletedEntries entry = new DeletedEntries(-1L, tableName, id, now, now);
System.out.println(entry);
// deletedEntriesDao.insert(entry);
}
}
这是我beans.xml文件的一部分:
<aop:aspectj-autoproxy>
<aop:include name="mysqlDbCheckAspect" />
<aop:include name="daoLoggerAspect" />
<aop:include name="controllerSecurityAspect" />
<aop:include name="deletedStorageAspect" />
</aop:aspectj-autoproxy>
通过注释掉deletedStorageAspect,我可以恢复完整功能。
是什么原因导致这种行为?为什么在映射上使用aspect时无法识别?Controller上不允许使用aspect吗?
希望能得到一些帮助,谢谢。
中添加
proxy-target-class=true`。 - M. Deinum