【问题标题】:Exists any <jaxws:endpoint /> annotation?是否存在任何 <jaxws:endpoint /> 注释?
【发布时间】:2011-08-01 17:41:46
【问题描述】:

我在 JBoss 5.1 中使用 CXFSpring 来发布和使用我的 WebServices。一切正常。

但是,有一件事情我觉得很乏味:在 applicationContext.xml 中为每个 WebService 放置一个 jaxws:endpoint 标签。

真的没有办法用注释来做到这一点吗?谢谢大家。

【问题讨论】:

    标签: java spring jax-ws cxf


    【解决方案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 调用此端点,例如“localhost:8080/api/MyService”

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

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

    BusFactory.newInstance().createBus()
    

    【讨论】:

      【解决方案2】:

      some annotations配置的东西你也可以放在&lt;jaxws:endpoint&gt;里面。声明一个 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...
      

      【讨论】:

      • 就像你说的,如果存在端点注释会非常好。我不明白这是如何尚未创建的。
      猜你喜欢
      • 2020-07-11
      • 2021-10-16
      • 2020-10-28
      • 2019-01-13
      • 1970-01-01
      • 2021-10-20
      • 2016-10-31
      • 2022-08-14
      • 2018-02-06
      相关资源
      最近更新 更多