java - 引起:java.lang.illegalArgumentException
问题描述
尝试使用 Junit 测试使用 Spring Rest Docs 生成文档,但我遇到了这些错误,我无法确定它来自哪里。我是一名初级开发人员,因此缺乏经验可能是其中的一部分。
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83)
at org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener.prepareTestInstance(SpringBootDependencyInjectionTestExecutionListener.java:47)
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'ALC012Client' defined in URL [jar:file:/C:/ProgramData/Maven/.m2/repository/com/jbhunt/order/lib_ordermanagement_alc012/2.0.2/lib_ordermanagement_alc012-2.0.2.jar!/com/jbhunt/ordermanagement/order/alc012/client/ALC012Client.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'servicePortConfiguration': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'servicePortConfiguration': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:137)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:409)
Caused by: java.lang.IllegalArgumentException
at com.sun.xml.ws.client.RequestContext.setEndPointAddressString(RequestContext.java:145)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.jvnet.ws.message.BasePropertySet$MethodAccessor.set(BasePropertySet.java:249)
at org.jvnet.ws.message.BasePropertySet$MapView.put(BasePropertySet.java:325)
at org.jvnet.ws.message.BasePropertySet$MapView.put(BasePropertySet.java:280)
at org.jvnet.ws.message.BaseDistributedPropertySet$DistributedMapView.put(BaseDistributedPropertySet.java:250)
at org.jvnet.ws.message.BaseDistributedPropertySet$DistributedMapView.put(BaseDistributedPropertySet.java:212)
at com.jbhunt.ordermanagement.order.alc012.configuration.ServicePortConfiguration.oec170Port(ServicePortConfiguration.java:45)
at com.jbhunt.ordermanagement.order.alc012.configuration.ServicePortConfigurationinitServicePortConfiguration(ServicePortConfiguration.java:33)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:366)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:311)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:134)
... 182 more
我不能显示太多代码,因为它是公司代码,但这里是注释和一些代码。我主要只是想找出问题可能来自哪里。
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@Transactional
public class DocumentControllerTest {
@Autowired
PIDCredentials pidCredentials;
@MockBean
EOIClient eooiClient;
@MockBean
private DocumentService documentService;
@Autowired
private WebApplicationContext webApplicationContext;
@Rule
public final JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation("target/generated-snippets");
@Autowired
private ObjectMapper objectMapper = new ObjectMapper();
private MockMvc mockMvc;
private RestDocumentationResultHandler documentResultHandler;
@Test
public void testfindallDocumentClasses() throws Exception {
Map<String, String> documentListDTO = null;
Mockito.when(documentService.findAllDocumentClasses()).thenReturn(documentListDTO);
this.mockMvc.perform(get("/search/findalldocumentclasses")
.accept(MediaType.APPLICATION_JSON)
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andDo(document("find-all-document-classes"));
}
}
解决方案
尝试 mvn clean package 和 mvn clean install,因为在尝试部署您的代码时似乎有些东西。
推荐阅读
- c++ - C++ lambda 不推断函数重载
- python - how to fetch the data of each excel row into html templates?
- python - Reordering the list based on values from another list?
- c++ - C++ Why can I not save this pointer to a reference?
- swift - 如何在 SwiftUI 中向 Viewmodifiers 添加闭包?
- git - 有没有办法删除我的电子邮件表单 git commits?
- python - 部署的 django 应用程序上的 500 错误,调试设置为 False
- javascript - 无法从内部承诺加入 socket.io 中的房间
- python - 当我尝试建立与数据库的连接时 ModuleNotFoundError: No module named 'mysql'
- android - 如何在 laravel 中设置 Sanctum 以使用 Android 应用程序?收到 419 错误