my own spring boot training project was fine before dinner yesterday afternoon, but I didn"t do anything after I came back with a good log
. Life and death just didn"t work. Baidu spent the night looking for
project structure
Log Code
@Aspect // bean
@Component // beancontrllerservice,service
@Order(3) // ORDER
public class MyLog{
private Logger log = LoggerFactory.getLogger(this.getClass());
// execution
@Pointcut("execution(public * com.sc.starry_sky.*.*.*.*(..))")
private void controllerAspect(){}
//method
@Before(value = "controllerAspect()")
public void methodBefore(JoinPoint joinPoint){
ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = requestAttributes.getRequest();
//
log.info("==============================");
log.info(":"+request.getRequestURL().toString());
log.info(":"+request.getMethod());
log.info(":"+joinPoint.getSignature());
log.info(":"+ Arrays.toString(joinPoint.getArgs()));
log.info("==============================");
}
//
@AfterReturning(returning = "o",pointcut = "controllerAspect()")
public void methodAfterReturing(Object o ){
log.info("********************************************************");
log.info(":" + o); // ---responseEntity
log.info("********************************************************");
}
}
pom file
<!-- AOP -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
</dependency>
contorller modifiers are all public
@Controller
public class Login extends BaseController {
@PostMapping("/doLogin")
@ResponseBody
public Map<String,Object> doLogin(String name){
HashMap<String, Object> resultMap = new HashMap<String, Object>();
try{
PageData user = this.getPageData();
UsernamePasswordToken token = new UsernamePasswordToken(user.getString("username"), user.getString("password"));
SecurityUtils.getSubject().login(token);
resultMap.put("status", 200);
resultMap.put("message", "");
return resultMap;
}catch(Exception e){
resultMap.put("status", 500);
resultMap.put("message", e.getMessage());
return resultMap;
}
}
@GetMapping("/loginPage")
public ModelAndView loginPage(String name){
ModelAndView mv = new ModelAndView();
System.out.println("in loginPage**************************************************");
mv.setViewName("login-regist");
return mv;
}
@GetMapping("/unauthorized")
public ModelAndView unauthorized(String name){
ModelAndView mv = new ModelAndView();
mv.setViewName("login-regist");
return mv;
}
}
when it came into effect before, there were not so many things. The following jar packages are all solutions searched on the Internet later. All the methods have been tried, but I really don"t know what happened.