我有 2 个 Web 服务类,我打算使用 Apache CXF 将它们公开为 SOAP 服务。其中一项服务将另一项服务作为其运营的一部分。我已经在我的 Grails 应用程序中设置了 Apache CXF(没有插件),并通过 resources.groovy
设置了我的 Web 服务(Spring Bean DSL)。
假设我有以下类(class):
@WebService
BookService {
//class definition
}
和:
@WebService
LibraryService {
BookService bookService
//class definition
}
我在我的
resources.groovy
中声明它们如下(省略命名空间声明):bookService(BookService)
jaxws.endpoint(id: 'bookService', implementor: "#bookService",
address: '/book')
libraryService(LibraryService) {
bookService = ref('bookService')
}
jaxws.endpoint(id: 'libraryService', implementor: "#libraryService",
address: '/library')
但是,每次我运行我的应用程序(通过
grails run-app
)我都会得到 IllegalAnnotationsException
:Caused by IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions
->> 106 | check in com.sun.xml.bind.v2.runtime.IllegalAnnotationsException$Builder
我不明白它为什么会发生。我是 Apache CXF 的新手,所以我希望有人能启发我。
更新:
我发现 CXF 会为我在服务类中声明的任何私有(private)字段抛出异常,除非它们是用
@XmlRootElement
注释的类型。 .这很奇怪。
最佳答案
为了解决这个问题,我所做的是 define a service endpoint interfaces (SEIs) ,对于我的服务,它们几乎只是 Java/Groovy 接口(interface)。我不确定问题是由于 Groovy 在后台添加的功能,还是 CXF 的 JAX-WS 实现或规范本身确实存在问题,但即使在将我的服务转换为 Java 之后,我仍然得到错误。
因此,LibraryService
特别是现在看起来像:
@WebService
interface LibraryService {
//class definition
}
以及具体实现:
@WebService
class LibraryServiceImpl implements LibraryService {
BookService bookService
//class definition
}
和bean定义:
libraryService(LibraryServiceImpl) {
bookService = ref('bookService')
}
jaxws.endpoint(id: 'libraryService', implementor: "#libraryService",
address: '/library')
关于spring - 当我添加对其他 bean 的引用时,为什么 Apache CXF 会抛出 IllegalAnnotationsException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29160128/