简体   繁体   中英

Eclipse tomcat on web application start java.lang.ClassNotFoundException: org.mockito.Mockito

I can not start web app in eclipse embedded tomcat, but if I deploy war file in standalone tomcat then it works.

The exception I get is:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name  defined in class path resource Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Factory method threw exception; nested exception is java.lang.NoClassDefFoundError: org/mockito/Mockito

The file exception is referring to is annotated with @Configuration and is located in src/test/java; purpose of the file is to create mock beans for test cases.

The fix to the problem is this link:

How to prevent eclipse from deploying test classes on Tomcat?

The cause of the problem was, when eclipse was assembling a war file it would include src/test/java dir in it, and the dependencies were missing for test cases. because in pom dependencies for test had test which means that maven will not include those jar files in final bucked product meaning war file.

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