Cing
发布于 2021-10-31 / 228 阅读
0

Spring Boot 在 Windows 运行单元测试报错

Spring Boot 编写的程序,直接运行不报错,单元测试报错,Mac 下运行单元测试不报错,Windows 下报错,排除代码错误的原因

观察报错日志

Caused by: java.lang.NoClassDefFoundError: net/minidev/asm/FieldFilter
	at net.minidev.json.reader.JsonWriter.<clinit>(JsonWriter.java:157) ~[json-smart-2.3.jar:na]
	at net.minidev.json.JSONValue.<clinit>(JSONValue.java:527) ~[json-smart-2.3.jar:na]
	at com.jayway.jsonpath.spi.json.JsonSmartJsonProvider.<init>(JsonSmartJsonProvider.java:39) ~[json-path-2.4.0.jar:2.4.0]
	at com.jayway.jsonpath.internal.DefaultsImpl.jsonProvider(DefaultsImpl.java:21) ~[json-path-2.4.0.jar:2.4.0]
	at com.jayway.jsonpath.Configuration$ConfigurationBuilder.build(Configuration.java:231) ~[json-path-2.4.0.jar:2.4.0]
	at org.springframework.data.web.JsonProjectingMethodInterceptorFactory.<init>(JsonProjectingMethodInterceptorFactory.java:74) ~[spring-data-commons-2.4.2.jar:2.4.2]
	at org.springframework.data.web.ProjectingJackson2HttpMessageConverter.initProjectionFactory(ProjectingJackson2HttpMessageConverter.java:87) ~[spring-data-commons-2.4.2.jar:2.4.2]
	at org.springframework.data.web.ProjectingJackson2HttpMessageConverter.<init>(ProjectingJackson2HttpMessageConverter.java:72) ~[spring-data-commons-2.4.2.jar:2.4.2]
	at org.springframework.data.web.config.SpringDataWebConfiguration.extendMessageConverters(SpringDataWebConfiguration.java:169) ~[spring-data-commons-2.4.2.jar:2.4.2]
	at org.springframework.web.servlet.config.annotation.WebMvcConfigurerComposite.extendMessageConverters(WebMvcConfigurerComposite.java:144) ~[spring-webmvc-5.3.2.jar:5.3.2]
	at org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration.extendMessageConverters(DelegatingWebMvcConfiguration.java:123) ~[spring-webmvc-5.3.2.jar:5.3.2]
	at org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.getMessageConverters(WebMvcConfigurationSupport.java:844) ~[spring-webmvc-5.3.2.jar:5.3.2]
	at org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.requestMappingHandlerAdapter(WebMvcConfigurationSupport.java:648) ~[spring-webmvc-5.3.2.jar:5.3.2]
	at org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$EnableWebMvcConfiguration.requestMappingHandlerAdapter(WebMvcAutoConfiguration.java:407) ~[spring-boot-autoconfigure-2.4.1.jar:2.4.1]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_242]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_242]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_242]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_242]
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.3.2.jar:5.3.2]
	... 87 common frames omitted

发现json-smart-2.3.jar引起了报错,使用 Maven Helper 插件在 pom 中搜索这个 jar , 把这个 jar 排除掉,重新导入一下 pom, 再次运行单元测试,发现问题解决

image20210110212254123.png