常用注解:
aop的全部通知顺序是什么?spring boot或者spring boot2对aop的执行顺序影响是什么?
新建一个切面
@Aspect
@Component
public class MyAspect
{
@Before("execution(public int com.zzyy.study.service.impl.CalcServiceImpl.*(..))")
public void beforeNotify()
{
System.out.println("******** @Before我是前置通知MyAspect");
}
@After("execution(public int com.zzyy.study.service.impl.CalcServiceImpl.*(..))")
public void afterNotify()
{
System.out.println("******** @After我是后置通知");
}
@AfterReturning("execution(public int com.zzyy.study.service.impl.CalcServiceImpl.*(..))")
public void afterReturningNotify()
{
System.out.println("********@AfterReturning我是返回后通知");
}
@AfterThrowing("execution(public int com.zzyy.study.service.impl.CalcServiceImpl.*(..))")
public void afterThrowingNotify()
{
System.out.println("********@AfterThrowing我是异常通知");
}
@Around("execution(public int com.zzyy.study.service.impl.CalcServiceImpl.*(..))")
public Object around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable
{
Object retValue = null;
System.out.println("我是环绕通知之前AAA");
retValue = proceedingJoinPoint.proceed();
System.out.println("我是环绕通知之后BBB");
return retValue;
}
}
spring4+springboot1.5.9
@SpringBootTest
@RunWith(SpringRunner.class) //1.5.9
public class T1
{
@Autowired
private CalcService service;
System.out.println("spring版本:"+ SpringVersion.getVersion()+"\t"+"SpringBoot版本:"+ SpringBootVersion.getVersion());
System.out.println();
calcService.div(10,2);
}
@WebServlet("/hello")
来标注,并且指明要拦截哪些路径package com.ldc.servlet;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/hello")
public class HelloServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.getWriter().write("hello...");
}
}
@WebFilter
注解、注册Listener用@WebListener
注解;如果在注册的时候,需要一些初始化参数,我们就可以用@WebInitParam
注解