调用SOAP服务应用程序只在我们的pre-prod环境中抛出以下错误。代码在dev和staging中工作。我们完全被困在这里了。
应用程序甚至没有部署在pre-prod环境中。我们尝试放置调试日志,并找到它失败的地方,WebServiceGateWaySupport
中定义的方法是setDefaultUri
等。由于这个问题只出现在一个实例上,我们不确定该怎么办。
下面给出了正在抛出的异常。
异常:
java.lang.NullPointerException
at org.springframework.ws.client.core.support.WebServiceGatewaySupport.setDefaultUri(WebServiceGatewaySupport.java:92)
at com.company.cabs.App.mapper.client.soapclient.AppClientConfiguration.setAppClient(AppClientConfiguration.java:53)
at com.company.cabs.App.mapper.client.soapclient.AppClientConfiguration$$EnhancerBySpringCGLIB$$d9f7933.CGLIB$setAppClient$0(<generated>)
at com.company.cabs.App.mapper.client.soapclient.AppClientConfiguration$$EnhancerBySpringCGLIB$$d9f7933$$FastClassBySpringCGLIB$$d3fe050c.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331)
at com.company.cabs.App.mapper.client.soapclient.AppClientConfiguration$$EnhancerBySpringCGLIB$$d9f7933.setAppClient(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:638)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:955)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:731)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1303)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1292)
at com.company.cabs.mpd.event.consumer.StarterApplication.main(StarterApplication.java:17)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:108)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:65)
AppClientConfiguration.class
@Configuration
public class AppClientConfiguration {
.....
@Bean
public AppClient setAppClient(Jaxb2Marshaller marshaller, AppClient client) throws NoSuchAlgorithmException, KeyManagementException {
client.setDefaultUri(defaultUri); //Error is being thrown here
client.setMarshaller(marshaller);//Error is being thrown here
client.setUnmarshaller(marshaller);//Error is being thrown here
client.getWebServiceTemplate().setMessageSender(webServiceMessageSender());//Error is being thrown here
client.getWebServiceTemplate().setCheckConnectionForError(false);//Error is being thrown here
client.getWebServiceTemplate().setCheckConnectionForFault(false);//Error is being thrown here
ClientInterceptor[] interceptors = {new AppClientInterceptor()};
client.setInterceptors(interceptors);
return client;
}
....
}
AppClient.java
@Component
public class AppClient extends WebServiceGatewaySupport {
....
}
我们的解决方案是手动创建一个AppClient
类对象。
- 从
AppClient.java
类中删除@Component
注释 AppClientConfiguration.java
class内部
@Bean
public AppClient setAppClient(Jaxb2Marshaller marshaller) throws NoSuchAlgorithmException, KeyManagementException {
AppClient client = new AppClient();//Manually creating the object
client.setDefaultUri(defaultUri);
client.setMarshaller(marshaller);
client.setUnmarshaller(marshaller);
............
...........
return client;
}
不确定前一个在其他实例中如何工作。但是,这种方法是有效的。