简体   繁体   中英

Autowired fields in aspect class are null in test mode

I use Spring boot and in ma aspect class i got two fields wich has @Autowired annotation. When I run code then it works fine but when i run test for this class then this two autowired fields are null. Can someone tell what I need to do to fix that? I'm sorry for lack of code but today I don't have access to this.

well, having in mind the fact that your question is not clear at all, here are some options that you could potentially miss in your test code:

  1. You are not mocking them or mocking them but not injecting
  2. You are not using injections in your test code at all

PS please read and understand more about dependency injection (@Autowired) of Spring Boot applications

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM