BeanNotOfRequiredTypeException due to autowired fields

前端 未结 9 1264
长发绾君心
长发绾君心 2020-12-02 12:07

I\'m still new to Spring MVC and while building my test project, I got this message from Tomcat logs:

SEVERE: Exception sending context initialized event to          


        
9条回答
  •  情书的邮戳
    2020-12-02 12:51

    I also had this problem with some @SpringBootTest classes that were testing endpoints. The endpoints had a dependency on a DB Service that has @Transactional on a few methods.

    Because of the @Transactional, Spring intercepts that and creates a proxy class, so Spock (or junit) would struggle to inject the correct mock.

    My workaround was to push the DB Service down one layer and have plain Spock tests around the middle layer which aren't affected by this.

提交回复
热议问题