Java 存在任何<;jaxws:endpoint/>;注释?
我正在使用CXF和Spring在jboss5.1中发布和使用我的web服务。一切正常 然而,我认为有一件事非常乏味:为applicationContext.xml中的每个web服务放置jaxws:endpoint标记 真的没有办法用注解做到这一点吗?谢谢大家。这里有一些配置,您也可以将它们放入Java 存在任何<;jaxws:endpoint/>;注释?,java,spring,jax-ws,cxf,Java,Spring,Jax Ws,Cxf,我正在使用CXF和Spring在jboss5.1中发布和使用我的web服务。一切正常 然而,我认为有一件事非常乏味:为applicationContext.xml中的每个web服务放置jaxws:endpoint标记 真的没有办法用注解做到这一点吗?谢谢大家。这里有一些配置,您也可以将它们放入中。一个声明CXF端点的注释会更好 您可以使用代码而不是SpringXML来配置端点。如果你有很多重复的配置可以考虑,这会很方便。或者,如果在不同的环境中对某些端点进行了不同的配置 例如: @Autowir
中。一个声明CXF端点的注释会更好
您可以使用代码而不是SpringXML来配置端点。如果你有很多重复的配置可以考虑,这会很方便。或者,如果在不同的环境中对某些端点进行了不同的配置
例如:
@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在中指出的那样。但是,只有当应用程序中只有一个端点时(至少我没有成功配置多个端点),此解决方案才有可能实现 其中MyServicePortType是具有@WebService注释的类。然后为类似“localhost:8080/api/MyService”的URL调用该端点 当然,这些@Bean声明可以放在任何其他spring配置类中 与复制的原始解决方案相反,我建议使用工厂方法而不是直接的“new SpringBus()”,来实例化总线(cxf Bean):
正如您所说,如果存在端点的注释,那将非常好。我不明白这是怎么回事,但我还没有创造出来。
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;
}
BusFactory.newInstance().createBus()