存在任何 注释?
问题描述:
我使用CXF与春发布和消费Web服务我在的JBoss 5.1。一切正常。存在任何<jaxws:endpoint />注释?
然而,有这就是我觉得非常乏味的一件事:把一个JAXWS:在applicationContext.xml中端点标签为每个WebService的。
真的没有办法做到这一点与注释?谢谢大家。
答
有some annotations配置的东西,你也可以把<jaxws:endpoint>
。声明CXF端点的注释很好。
您可以使用代码而不是Spring XML来配置端点。如果你有很多可以分解的重复配置,这可能很方便。或者如果您在不同的环境中配置了不同的端点。
例如:
@Autowired var authImpl: Auth = _
@Autowired var faultListener: FaultListener = _
def initWebServices() {
var sf: JaxWsServerFactoryBean = _
val propMap = mutable.HashMap[String, AnyRef]("org.apache.cxf.logging.FaultListener"->faultListener.asInstanceOf[AnyRef])
sf = new JaxWsServerFactoryBean
sf.setServiceBean(authImpl)
sf.setAddress("/auth")
sf.setServiceName(new QName("http://auth.ws.foo.com/", "auth", "AuthService"))
sf.setProperties(propMap)
sf.create
// more services...
答
随着时间通,出现了一些新的可能性。使用CXF/SpringBoot(SpringBoot:1.2.3,CXF:3.10,Spring:4.1.6)有一个很好的选择,为了摆脱cxf-servlet.xml中的jaxws:endpoint配置,如下所示: jonashackt在nabble.com中指出。但是,只有在应用程序中只有一个端点时(至少我没有成功配置多个端点),该解决方案才有可能。
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Bean
public ServletRegistrationBean dispatcherServlet() {
CXFServlet cxfServlet = new CXFServlet();
return new ServletRegistrationBean(cxfServlet, "/api/*");
}
@Bean(name="cxf")
public SpringBus springBus() {
return new SpringBus();
}
@Bean
public MyServicePortType myService() {
return new MyServiceImpl();
}
@Bean
public Endpoint endpoint() {
EndpointImpl endpoint = new EndpointImpl(springBus(), myService());
endpoint.publish("/MyService");
return endpoint;
}
其中MyServicePortType是具有@WebService注释的类。然后这个Endpoint被称为URL的“localhost:8080/api/MyService”
当然,这些@Bean声明可以放在任何其他spring配置类中。
在违背复制原来的解决方案,我建议使用,而不是直接的工厂方法来实例化总线(CXF-Bean)的“新SpringBus()”:
BusFactory.newInstance().createBus()
就像你说的,会非常好,如果存在端点的注释。我不明白这是怎么产生的。 – 2011-04-08 23:42:30