在Grails CXF服务中使用@WebService抛出异常

时间:2015-12-04 11:32:09

标签: web-services grails cxf

我正在尝试使用Grails中的CFX生成Web服务。

我添加了编译":cxf:2.1.1"到BuildConfig.groovy并创建了一个服务:

package servicetest

import grails.transaction.Transactional
import javax.jws.*;
import org.grails.cxf.utils.EndpointType

@Transactional
class TestService {

    static expose = EndpointType.JAX_WS

    @WebMethod( operationName="createUpdateUser" )
    @WebResult( name="result" )   
    def serviceMethod() {

    }
}

这没关系。但是,我想在生成的WSDL中更改目标命名空间。为此,我添加@WebService:

package servicetest

import grails.transaction.Transactional
import javax.jws.*;
import org.grails.cxf.utils.EndpointType

@Transactional
@WebService(name = 'CustomerServiceWsdlEndpoint',
    targetNamespace = 'http://test.cxf.grails.org/',
    serviceName = 'CustomerServiceWsdlEndpoint',
    portName = 'CustomerServiceWsdlPort')
class TestService {

    static expose = EndpointType.JAX_WS

    @WebMethod( operationName="createUpdateUser" )
    @WebResult( name="result" )   
    def serviceMethod() {

    }
}

但是,当我启动Grails应用程序时,收到以下错误消息:

|Running Grails application
Error |
2015-12-04 11:21:07,506 [localhost-startStop-1] ERROR [localhost].[/ServiceTest]  - StandardWrapper.Throwable
Message: Error creating bean with name 'testServiceBean': Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.apache.cxf.endpoint.Server org.apache.cxf.jaxws.JaxWsServerFactoryBean.create()] threw exception; nested exception is org.apache.cxf.service.factory.ServiceConstructionException
    Line | Method
->>  593 | createApplicationContext in grails.spring.BeanBuilder
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|     53 | loadAdditionalConfig     in org.grails.cxf.servlet.GrailsCxfServlet
|     25 | init . . . . . . . . . . in     ''
|    262 | run                      in java.util.concurrent.FutureTask
|   1145 | runWorker . . . . . . .  in java.util.concurrent.ThreadPoolExecutor
|    615 | run                      in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run . . . . . . . . . .  in java.lang.Thread
Caused by BeanDefinitionStoreException: Factory method [public org.apache.cxf.endpoint.Server org.apache.cxf.jaxws.JaxWsServerFactoryBean.create()] threw exception; nested exception is org.apache.cxf.service.factory.ServiceConstructionException
->>  593 | createApplicationContext in grails.spring.BeanBuilder
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|     53 | loadAdditionalConfig     in org.grails.cxf.servlet.GrailsCxfServlet
|     25 | init . . . . . . . . . . in     ''
|    262 | run                      in java.util.concurrent.FutureTask
|   1145 | runWorker . . . . . . .  in java.util.concurrent.ThreadPoolExecutor
|    615 | run                      in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run . . . . . . . . . .  in java.lang.Thread
Caused by ServiceConstructionException: null
->>  336 | initialize               in org.apache.cxf.jaxb.JAXBDataBinding
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|     86 | initializeDataBindings   in org.apache.cxf.service.factory.AbstractServiceFactoryBean
|    467 | buildServiceFromClass .  in org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean
|    712 | buildServiceFromClass    in org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean
|    527 | initializeServiceModel . in org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean
|    261 | create                   in     ''
|    215 | create . . . . . . . . . in org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean
|    102 | createEndpoint           in org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory
|    159 | create . . . . . . . . . in org.apache.cxf.frontend.ServerFactoryBean
|    211 | create                   in org.apache.cxf.jaxws.JaxWsServerFactoryBean
|    593 | createApplicationContext in grails.spring.BeanBuilder
|     53 | loadAdditionalConfig     in org.grails.cxf.servlet.GrailsCxfServlet
|     25 | init . . . . . . . . . . in     ''
|    262 | run                      in java.util.concurrent.FutureTask
|   1145 | runWorker . . . . . . .  in java.util.concurrent.ThreadPoolExecutor
|    615 | run                      in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run . . . . . . . . . .  in java.lang.Thread
Caused by IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
->>  106 | check                    in com.sun.xml.bind.v2.runtime.IllegalAnnotationsException$Builder
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    460 | getTypeInfoSet           in com.sun.xml.bind.v2.runtime.JAXBContextImpl
|    292 | <init> . . . . . . . . . in     ''
|    139 | <init>                   in     ''
|   1138 | build . . . . . . . . .  in com.sun.xml.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder
|    162 | createContext            in com.sun.xml.bind.v2.ContextFactory
|    248 | newInstance . . . . . .  in javax.xml.bind.ContextFinder
|    235 | newInstance              in     ''
|    432 | find . . . . . . . . . . in     ''
|    637 | newInstance              in javax.xml.bind.JAXBContext
|    347 | run . . . . . . . . . .  in org.apache.cxf.common.jaxb.JAXBContextCache$2
|    345 | run                      in     ''
|    246 | getCachedContextAndSchemas in org.apache.cxf.common.jaxb.JAXBContextCache
|    479 | createJAXBContextAndSchemas in org.apache.cxf.jaxb.JAXBDataBinding
|    334 | initialize . . . . . . . in     ''
|     86 | initializeDataBindings   in org.apache.cxf.service.factory.AbstractServiceFactoryBean
|    467 | buildServiceFromClass .  in org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean
|    712 | buildServiceFromClass    in org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean
|    527 | initializeServiceModel . in org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean
|    261 | create                   in     ''
|    215 | create . . . . . . . . . in org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean
|    102 | createEndpoint           in org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory
|    159 | create . . . . . . . . . in org.apache.cxf.frontend.ServerFactoryBean
|    211 | create                   in org.apache.cxf.jaxws.JaxWsServerFactoryBean
|    593 | createApplicationContext in grails.spring.BeanBuilder
|     53 | loadAdditionalConfig     in org.grails.cxf.servlet.GrailsCxfServlet
|     25 | init . . . . . . . . . . in     ''
|    262 | run                      in java.util.concurrent.FutureTask
|   1145 | runWorker . . . . . . .  in java.util.concurrent.ThreadPoolExecutor
|    615 | run                      in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run . . . . . . . . . .  in java.lang.Thread
Error |
2015-12-04 11:21:07,595 [localhost-startStop-1] ERROR [localhost].[/ServiceTest]  - Servlet /ServiceTest threw load() exception
Message: 1 counts of IllegalAnnotationExceptions
    Line | Method
->>  106 | check                       in com.sun.xml.bind.v2.runtime.IllegalAnnotationsException$Builder
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    460 | getTypeInfoSet              in com.sun.xml.bind.v2.runtime.JAXBContextImpl
|    292 | <init> . . . . . . . . . .  in     ''
|    139 | <init>                      in     ''
|   1138 | build . . . . . . . . . . . in com.sun.xml.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder
|    162 | createContext               in com.sun.xml.bind.v2.ContextFactory
|    248 | newInstance . . . . . . . . in javax.xml.bind.ContextFinder
|    235 | newInstance                 in     ''
|    432 | find . . . . . . . . . . .  in     ''
|    637 | newInstance                 in javax.xml.bind.JAXBContext
|    347 | run . . . . . . . . . . . . in org.apache.cxf.common.jaxb.JAXBContextCache$2
|    345 | run                         in     ''
|    246 | getCachedContextAndSchemas  in org.apache.cxf.common.jaxb.JAXBContextCache
|    479 | createJAXBContextAndSchemas in org.apache.cxf.jaxb.JAXBDataBinding
|    334 | initialize . . . . . . . .  in     ''
|     86 | initializeDataBindings      in org.apache.cxf.service.factory.AbstractServiceFactoryBean
|    467 | buildServiceFromClass . . . in org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean
|    712 | buildServiceFromClass       in org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean
|    527 | initializeServiceModel . .  in org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean
|    261 | create                      in     ''
|    215 | create . . . . . . . . . .  in org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean
|    102 | createEndpoint              in org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory
|    159 | create . . . . . . . . . .  in org.apache.cxf.frontend.ServerFactoryBean
|    211 | create                      in org.apache.cxf.jaxws.JaxWsServerFactoryBean
|    593 | createApplicationContext .  in grails.spring.BeanBuilder
|     53 | loadAdditionalConfig        in org.grails.cxf.servlet.GrailsCxfServlet
|     25 | init . . . . . . . . . . .  in     ''
|    262 | run                         in java.util.concurrent.FutureTask
|   1145 | runWorker . . . . . . . . . in java.util.concurrent.ThreadPoolExecutor
|    615 | run                         in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run . . . . . . . . . . . . in java.lang.Thread

有人可以告诉我我做错了什么,或者是否有其他方法可以设置目标命名空间?

谢谢,

卡尔

1 个答案:

答案 0 :(得分:0)

要解决问题,您需要创建一个Web服务接口,然后在您的服务类中实现它。

@WebService
interface TestServiceInterface {

  def serviceMethod() 
}



@WebService(name = 'CustomerServiceWsdlEndpoint',
          targetNamespace = 'http://test.cxf.grails.org/',
          serviceName = 'CustomerServiceWsdlEndpoint',
          portName = 'CustomerServiceWsdlPort')
class TestService implements TestServiceInterface {

static expose = EndpointType.JAX_WS

@WebMethod( operationName="createUpdateUser" )
@WebResult( name="result" )   
 def serviceMethod() {
 }
}

有关更多信息,请转到link