没任何日志的出现

来源:2-2 使用AOP处理请求(中)

qq_人不犯er枉少年_03735473

2018-04-04 17:35

package liang.test.aspect;


import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Aspect
@Component
public aspect HttpCliet {

   private final static Logger logger= LoggerFactory.getLogger(HttpCliet.class);
   @Pointcut("execution(public * liang.test.controller.GirlController.*(..))")
   public void log(){
   }

   @Before("log()")
   public void logb(){
       logger.info("befor");
   }
   @After("log()")
   public void log1(){
       logger.info("After");

   }

}

 

package liang.test.controller;

import liang.test.properties.Girl;
import liang.test.repository.GirlsRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@RequestMapping("/girl")
public class GirlController {

   @Autowired
   private Girl girl;
   @Autowired
   private GirlsRepository girlsRepository;

   @PostMapping("/insert")
   public Girl insert(@Valid Girl girl, BindingResult bindingResult){
       if (bindingResult.hasErrors()){
           System.out.println(bindingResult.getFieldError().getDefaultMessage());
           return null;
       }
       girl.setAge(girl.getAge());
       girl.setName(girl.getName());
       return girlsRepository.save(girl);
   }

}

写回答 关注

2回答

  • Ashwood_Edward
    2018-04-07 16:53:22
    已采纳
    @Aspect
    @Component
    public aspect HttpCliet {

    问题在这里: 类的定义

    解决: public class HttpClient{...}

    望采纳

    qq_人不犯...

    非常感谢!

    2018-04-07 20:29:41

    共 2 条回复 >

  • qq_人不犯er枉少年_03735473
    2018-04-07 18:48:00
    com.example.demo.aspectorg.slf4j.Loggerorg.slf4j.LoggerFactoryGirlAspect {
    
        Logger =LoggerFactory.(GirlAspect.)()
        (){
    
        }
    
        (= )
        (){
    
            .info()}
    
        (= )
        (){
            .info()}
    }


Spring Boot进阶之Web进阶

《2小时学习Spring Boot》之进阶教程,针对Web方面的相关技巧

104039 学习 · 393 问题

查看课程

相似问题