Как исправить ошибку в javax.в формате XML.с WS.WebServiceException: Ява.яз..NullPointerException?


Я запускаю приложение 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:UsersMayagitapp-servicestargetclasses started by Maya in C:UsersMayagitapp-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 находится в применении.класс, который выглядит следующим образом:

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;
    }

}
Я искал по всему Интернету, чтобы найти решение, но без всякого успеха. Не могли бы вы помочь мне исправить это исключение?

Полная трассировка стека находится здесь: полная трассировка стека

3 3

3 ответа:

Проблема заключается в установке конечной точки в методе 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

Орг.апаш.в CXF.общий.утиль.ASMHelper: -

public static String getClassCode(Class<?> cl) {
        if (cl == Void.TYPE) {
            return "V";
        }
        if (cl.isPrimitive()) {

В моем случае проблема была в аннотации в классе ServiceInterface: need

@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE) 

Вместо

@SOAPBinding(parameterStyle=SOAPBinding.ParameterStyle.WRAPPED)

Для методов Соми.

Эта ошибка может произойти, если объект, возвращаемый службой, не имеет пустого конструктора.

Просто убедитесь, что все ваши dto являются пустыми конструкторами.