开发者社区> 问答> 正文

SpringMVC中配置AOP拦截controller:报错

小弟对spring aop不熟,现在有个项目需要记录日志,不想每个controller中去写,就想使用AOP,结果呢,配置后启动没错,但不出来

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd ">

	<!-- DispatcherServlet Context: defines this servlet's request-processing 
		infrastructure -->

	<!-- Scans within the base package of the application for @Components to 
		configure as beans -->
	<!-- @Controller, @Service, @Configuration, etc. -->
	<aop:aspectj-autoproxy proxy-target-class="true" />
	<mvc:resources location="/css/" mapping="/css/**" />
	<mvc:resources location="/img/" mapping="/img/**" />
	<mvc:resources location="/js/" mapping="/js/**" />
	<mvc:resources location="/json/" mapping="/json/**" />
	<mvc:resources location="/jquery-easyui-1.3.3/" mapping="/jquery-easyui-1.3.3/**" />
	<bean id="multipartResolver"
		class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
		<property name="maxUploadSize" value="100000000" />
	</bean>
</beans>
然后呢,AOP类
package com.*.windrunner.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class ControllerLogAspect {

	@Before(value = "execution(* com.*.windrunner.controller.*(..))")
	public void beforeMethod(JoinPoint point) {
		System.out.println("------test aop before");
	}

}
这个里面因为有公司项目,所以把包名用*号代替了,见谅!!现在不输,求帮忙

展开
收起
kun坤 2020-06-06 17:49:54 678 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载