26 Eylül 2021 Pazar

SpringBoot ServletRegistrationBean Sınıfı

Örnek
Şöyle yaparız
import javax.xml.ws.Endpoint;
import org.apache.cxf.Bus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
import com.cfxconsumer.soapcxfconsumer.ws.HelloWorldWS;

@Configuration
@ImportResource({ "classpath:META-INF/cxf/cxf.xml" })
public class CxfWebServiceConfig {
  @Autowired
  private Bus cxfBus;

  @Bean
  public ServletRegistrationBean cxfServlet() {
    org.apache.cxf.transport.servlet.CXFServlet cxfServlet =
new org.apache.cxf.transport.servlet.CXFServlet();
    ServletRegistrationBean def = new ServletRegistrationBean<>(cxfServlet, "/ws/*");
    def.setLoadOnStartup(1);
    return def;
  }

  @Bean
  public Endpoint helloWorldWebService(HelloWorldWS helloWorldWS) {
    EndpointImpl endpoint = new EndpointImpl(cxfBus, helloWorldWS);
    endpoint.setAddress("/helloWorldWS");
    endpoint.publish();
    return endpoint;
  }
}

Hiç yorum yok:

Yorum Gönder