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