Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/353.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何修复javax.xml.ws.WebServiceException:java.lang.NullPointerException?_Java_Web Services_Spring Boot_Cxf - Fatal编程技术网

如何修复javax.xml.ws.WebServiceException:java.lang.NullPointerException?

如何修复javax.xml.ws.WebServiceException:java.lang.NullPointerException?,java,web-services,spring-boot,cxf,Java,Web Services,Spring Boot,Cxf,我正在运行我的Spring Boot应用程序(mvn:Spring Boot:run),并获取下一个堆栈跟踪: \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v1.3.2.RELEASE) 2016-02-10 09:57:31.350

我正在运行我的Spring Boot应用程序(
mvn:Spring Boot:run
),并获取下一个堆栈跟踪:

 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.3.2.RELEASE)

2016-02-10 09:57:31.350  INFO 8868 --- [           main] com.comp.config.Application         : Starting Application on SOFT12 with PID 8868 (C:\Users\Maya\git\app-services\target\classes started by Maya in C:\Users\Maya\git\app-services)
2016-02-10 09:57:31.356  INFO 8868 --- [           main] com.comp.config.Application         : No active profile set, falling back to default profiles: default
2016-02-10 09:57:31.429  INFO 8868 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@7dd7f653: startup date [Wed Feb 10 09:57:31 MSK 2016]; root of context hierarchy
2016-02-10 09:57:33.174  INFO 8868 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Overriding bean definition for bean 'beanNameViewResolver' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration; factoryMethodName=beanNameViewResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter; factoryMethodName=beanNameViewResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter.class]]
2016-02-10 09:57:35.126  INFO 8868 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2016-02-10 09:57:35.151  INFO 8868 --- [           main] o.apache.catalina.core.StandardService   : Starting service Tomcat
2016-02-10 09:57:35.153  INFO 8868 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.0.30
2016-02-10 09:57:35.296  INFO 8868 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2016-02-10 09:57:35.296  INFO 8868 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 3871 ms
2016-02-10 09:57:36.401  INFO 8868 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean        : Mapping servlet: 'CXFServlet' to [/APPservice/*]
2016-02-10 09:57:36.408  INFO 8868 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'metricFilter' to: [/*]
2016-02-10 09:57:36.409  INFO 8868 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'characterEncodingFilter' to: [/*]
2016-02-10 09:57:36.409  INFO 8868 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2016-02-10 09:57:36.409  INFO 8868 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2016-02-10 09:57:36.410  INFO 8868 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'requestContextFilter' to: [/*]
2016-02-10 09:57:36.410  INFO 8868 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'webRequestLoggingFilter' to: [/*]
2016-02-10 09:57:36.410  INFO 8868 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'applicationContextIdFilter' to: [/*]
2016-02-10 09:57:37.028  INFO 8868 --- [           main] o.a.c.w.s.f.ReflectionServiceFactoryBean : Creating Service {http://new.webservice.namespace}CompServiceForPCO from WSDL: classpath:CompService.wsdl
2016-02-10 09:57:39.665  WARN 8868 --- [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ws' defined in com.comp.config.Application: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.xml.ws.Endpoint]: Factory method 'ws' threw exception; nested exception is javax.xml.ws.WebServiceException: java.lang.NullPointerException
2016-02-10 09:57:39.676  INFO 8868 --- [           main] o.apache.catalina.core.StandardService   : Stopping service Tomcat
2016-02-10 09:57:39.891 ERROR 8868 --- [           main] o.s.boot.SpringApplication               : Application startup failed
ws-method位于Application.class中,如下所示:

package com.comp.config;

import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
import org.springframework.boot.context.embedded.ServletRegistrationBean;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import com.comp.pcoserv.CompServiceEndPoindImpl;

import javax.xml.ws.Endpoint;


@Configuration
@EnableAutoConfiguration
public class Application  {

    public static final String SERVLET_MAPPING_URL_PATH = "/APPservice";
    public static final String SERVICE_NAME_URL_PATH = "/ws";

    @Autowired
    private ApplicationContext applicationContext;

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    @Bean
    public ServletRegistrationBean dispatcherServlet() {
        return new ServletRegistrationBean(new CXFServlet(), SERVLET_MAPPING_URL_PATH + "/*");
    }


    @Bean(name = Bus.DEFAULT_BUS_ID)
    /* <bean id="cxf" class="org.apache.cxf.bus.spring.SpringBus">*/
    public SpringBus springBus() {
        return new SpringBus();
    }

    @Bean
    /* <jaxws:endpoint id="app" implementor="com.dlizarra.app.ws.AppImpl" address="/app">*/
    public Endpoint ws() {
        //Bus bus = (Bus) applicationContext.getBean(Bus.DEFAULT_BUS_ID);


        Object implementor = new CompServiceEndPoindImpl();
        EndpointImpl endpoint = new EndpointImpl(springBus(), implementor);
        endpoint.publish(SERVICE_NAME_URL_PATH);
        endpoint.setWsdlLocation("CompService.wsdl");
        /*endpoint.getServer().getEndpoint().getInInterceptors().add(new LoggingInInterceptor());
        endpoint.getServer().getEndpoint().getOutInterceptors().add(new LoggingOutInterceptor());*/
        return endpoint;
    }

}
package com.comp.config;
导入org.apache.cxf.Bus;
导入org.apache.cxf.bus.spring.SpringBus;
导入org.apache.cxf.interceptor.logginInterceptor;
导入org.apache.cxf.interceptor.loggingOutinerCeptor;
导入org.apache.cxf.jaxws.EndpointImpl;
导入org.apache.cxf.transport.servlet.CXFServlet;
导入org.springframework.beans.factory.annotation.Autowired;
导入org.springframework.boot.SpringApplication;
导入org.springframework.boot.autoconfigure.EnableAutoConfiguration;
导入org.springframework.boot.autoconfigure.springboot应用程序;
导入org.springframework.boot.builder.SpringApplicationBuilder;
导入org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
导入org.springframework.boot.context.embedded.ServletRegistrationBean;
导入org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
导入org.springframework.boot.context.web.SpringBootServletInitializer;
导入org.springframework.context.ApplicationContext;
导入org.springframework.context.annotation.Bean;
导入org.springframework.context.annotation.Configuration;
导入org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
导入com.comp.pcoserv.CompServiceEndPoindImpl;
导入javax.xml.ws.Endpoint;
@配置
@启用自动配置
公共类应用程序{
公共静态最终字符串SERVLET_映射_URL_PATH=“/APPservice”;
公共静态最终字符串服务\u NAME\u URL\u PATH=“/ws”;
@自动连线
私有应用程序上下文应用程序上下文;
公共静态void main(字符串[]args){
SpringApplication.run(Application.class,args);
}
@豆子
public ServletRegistrationBean dispatcherServlet(){
返回新的ServletRegistrationBean(新的CXFServlet(),SERVLET\u映射\u URL\u路径+“/*”);
}
@Bean(name=Bus.DEFAULT\u-Bus\u-ID)
/* */
公共SpringBus SpringBus(){
返回新的SpringBus();
}
@豆子
/* */
公共端点ws(){
//Bus Bus=(Bus)applicationContext.getBean(Bus.DEFAULT\U Bus\U ID);
对象实现者=新的CompServiceEndPoindImpl();
EndpointImpl端点=新的EndpointImpl(springBus(),实现者);
发布(服务名称、URL、路径);
setWsdlLocation(“CompService.wsdl”);
/*endpoint.getServer().getEndpoint().getInInterceptors().add(新的LogginInInterceptor());
endpoint.getServer().getEndpoint().getOutiterCeptors().add(新的LoggingOutiterCeptor())*/
返回端点;
}
}
我搜索了整个互联网来寻找解决方案,但没有成功。你能帮我解决这个异常吗


完整堆栈跟踪如下:

问题在于方法ws()中端点的安装。那么在这一行之后呢

EndpointImpl endpoint = new EndpointImpl(springBus(), implementor);
对其调用
publish
会导致NullPointerException

错误跟踪:-

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.xml.ws.Endpoint]: Factory method 'ws' threw exception; nested exception is javax.xml.ws.WebServiceException: java.lang.NullPointerException

Caused by: javax.xml.ws.WebServiceException: java.lang.NullPointerException
    at org.apache.cxf.jaxws.EndpointImpl.doPublish(EndpointImpl.java:375) ~[cxf-rt-frontend-jaxws-3.1.5.jar:3.1.5]
    at org.apache.cxf.jaxws.EndpointImpl.publish(EndpointImpl.java:255) ~[cxf-rt-frontend-jaxws-3.1.5.jar:3.1.5]
扩展错误跟踪:-

Caused by: java.lang.NullPointerException: null
    at org.apache.cxf.common.util.ASMHelper.getClassCode(ASMHelper.java:212) ~[cxf-core-3.1.5.jar:3.1.5]
    at org.apache.cxf.jaxws.WrapperClassGenerator.generateMessagePart(WrapperClassGenerator.java:310) ~[cxf-rt-frontend-jaxws-3.1.5.jar:3.1.5]
    at org.apache.cxf.jaxws.WrapperClassGenerator.createWrapperClass(WrapperClassGenerator.java:224) ~[cxf-rt-frontend-jaxws-3.1.5.jar:3.1.5]
    at org.apache.cxf.jaxws.WrapperClassGenerator.generate(WrapperClassGenerator.java:132) ~[cxf-rt-frontend-jaxws-3.1.5.jar:3.1.5]
    at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.generatedWrapperBeanClass(JaxWsServiceFactoryBean.java:675) ~[cxf-rt-frontend-jaxws-3.1.5.jar:3.1.5]
    at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.getExtraClass(JaxWsServiceFactoryBean.java:645) ~[cxf-rt-frontend-jaxws-3.1.5.jar:3.1.5]
    at org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean.buildServiceFromWSDL(ReflectionServiceFactoryBean.java:417) ~[cxf-rt-wsdl-3.1.5.jar:3.1.5]
    at org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean.initializeServiceModel(ReflectionServiceFactoryBean.java:525) ~[cxf-rt-wsdl-3.1.5.jar:3.1.5]
    at org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean.create(ReflectionServiceFactoryBean.java:261) ~[cxf-rt-wsdl-3.1.5.jar:3.1.5]
    at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.create(JaxWsServiceFactoryBean.java:199) ~[cxf-rt-frontend-jaxws-3.1.5.jar:3.1.5]
    at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint(AbstractWSDLBasedEndpointFactory.java:102) ~[cxf-rt-frontend-simple-3.1.5.jar:3.1.5]
    at org.apache.cxf.frontend.ServerFactoryBean.create(ServerFactoryBean.java:168) ~[cxf-rt-frontend-simple-3.1.5.jar:3.1.5]
    at org.apache.cxf.jaxws.JaxWsServerFactoryBean.create(JaxWsServerFactoryBean.java:211) ~[cxf-rt-frontend-jaxws-3.1.5.jar:3.1.5]
    at org.apache.cxf.jaxws.EndpointImpl.getServer(EndpointImpl.java:460) ~[cxf-rt-frontend-jaxws-3.1.5.jar:3.1.5]
    at org.apache.cxf.jaxws.EndpointImpl.doPublish(EndpointImpl.java:338) ~[cxf-rt-frontend-jaxws-3.1.5.jar:3.1.5]
    ... 37 common frames omitted
org.apache.cxf.common.util.ASMHelper:-

public static String getClassCode(Class<?> cl) {
        if (cl == Void.TYPE) {
            return "V";
        }
        if (cl.isPrimitive()) {
公共静态字符串getClassCode(类cl){
if(cl==Void.TYPE){
返回“V”;
}
if(cl.isPrimitive()){

在我的例子中,问题在于ServiceInterface类中的注释:需要

@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE) 
而不是

@SOAPBinding(parameterStyle=SOAPBinding.ParameterStyle.WRAPPED)

对于somö方法。

当服务返回的对象没有空构造函数时,可能会发生此错误


请确保您的所有dto都是空构造函数。

Avis,首先感谢您的回复。但如何修复它?为什么“new EndpointImpl(springBus(),implementor)”不起作用?@5月12日查看我上面的更新答案。由于wsdl问题,服务似乎无法发布,因此在执行此操作时,它在(cl.isPrimitive(){c1为空。建议围绕WS()bean.Avis调试代码,非常感谢;您的回答引导了我正确的方向。因此问题出在
ServiceInterface
中的注释中:需要
@SOAPBinding(parameterStyle=SOAPBinding.parameterStyle.BARE)
而不是
@SOAPBinding(parameterStyle=SOAPBinding.parameterStyle.WRAPPED)