0
我使用REST控制器创建了测试Spring MVC应用程序。我想为我的某些方法应用方面,但是当这种方法被称为没有发生,我找不到原因。 这是我的配置和应用类:Spring Boot @Aspect J logging
@SpringBootApplication(scanBasePackages = "org.test")
@EnableAspectJAutoProxy
public class TestaopApplication {
public static void main(String[] args) {
SpringApplication.run(TestaopApplication.class, args);
}
}
这是我的切面类:
@Aspect
@Component
public class Logging {
private static final Logger logger = LoggerFactory.getLogger(GreetingController.class);
@Pointcut("execution(* org.test.restspring.model.Greeting.getCreatedDate(..))")
private void getDate(){}
@Before("getDate()")
public void beforeGettingDate(){
logger.info("Date is asked");
}
@After("getDate()")
public void afterGettingDate(){
logger.info("Date is received");
}
}
这是我简单的bean:
@Component
public class Greeting {
private long id;
private String content;
private Date created;
public Greeting() { }
public Greeting(long id, String content) {
this.id = id;
this.content = content;
this.created = Calendar.getInstance().getTime();
}
public long getId() {
return id;
}
public String getContent() {
return content;
}
public String getCreatedDate(){
return created.toString();
}
}
这是我的控制器:
@RestController
public class GreetingController {
private static final String template = "Hello, %s!";
private static final Logger logger = LoggerFactory.getLogger(GreetingController.class);
private final AtomicLong counter = new AtomicLong();
@RequestMapping("/greeting")
public Greeting greeting(@RequestParam(value="name", defaultValue="World") String name) {
Greeting response = new Greeting(counter.incrementAndGet(),
String.format(template, name));
logger.info(response.getCreatedDate());
return response;
}
}
请帮我解决这个问题。
我GOR一个错误,但是当我替换方法与@Pointcut不存在的(即方面没有被施加到方法) ,我没有错误。它是错误::无法写入HTTP消息:org.springframework.http.converter.HttpMessageNotWritableException:无法写入内容:找不到类org.springframework.aop.TrueClassFilter的序列化程序,并且没有发现创建BeanSerializer的属性(为了避免异常,禁用SerializationFeature.FAIL_ON_EMPTY_BEANS)) – Yuriy
我在我的getter和setter问候类。 – Yuriy