造成原因:java.lang.illegalArgumentException

时间:2019-04-18 16:36:01

标签: java exception junit spring-restdocs

尝试使用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"));
    }

}

1 个答案:

答案 0 :(得分:1)

尝试进行mvn全新安装和mvn全新安装,因为在尝试部署代码时似乎有些东西。