引起:java.lang.illegalArgumentException

问题描述 投票:-2回答:1

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

}
java exception junit spring-restdocs
1个回答
1
投票

尝试mvn clean package和mvn clean install,因为在尝试部署代码时似乎有些不对劲。

© www.soinside.com 2019 - 2024. All rights reserved.