存在任何<jaxws:endpoint>注释?</jaxws:endpoint>

时间:2011-04-08 18:22:08

标签: java spring jax-ws cxf

我正在使用 CXF Spring JBoss 5.1 中发布和使用我的Web服务。一切正常。

但是,有一件事我觉得非常乏味:在 applicationContext.xml 中为每个WebService添加 jaxws:endpoint 标记。

使用注释真的无法做到这一点吗?感谢所有人。

2 个答案:

答案 0 :(得分:2)

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...

答案 1 :(得分:1)

随着时间的推移,出现了一些新的可能性。

使用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批注的类。然后调用此端点以获取URL&#34; localhost:8080 / api / MyService&#34;

当然,这些@Bean声明可以放在任何其他spring配置类中。

与复制的原始解决方案相反,我建议使用工厂方法而不是直接&#34;新的SpringBus()&#34;来实例化总线(cxf-Bean):

BusFactory.newInstance().createBus()