Spring Boot register JAX-WS webservice as bean

后端 未结 4 1798
天命终不由人
天命终不由人 2021-01-03 01:47

In my spring boot ws based application I have created a jax-ws webservice following a contract first approach. The Web service is up but I cannot autowire my other beans ins

4条回答
  •  长情又很酷
    2021-01-03 02:13

    You don´t have to extend your Configuration from SpringBootServletInitializer, nor override configure() or onStartup() methods. And in no way you have to build something implementing WebApplicationInitializer. There are only few steps to do (you could also do all the steps in a seperate @Configuration-class, the class with @SpringBootApplication only needs to know, where this one is - e.g. via @ComponentScan).

    1. Register the CXFServlet in an ServletRegistrationBean
    2. Instantiate a SpringBus
    3. Instantiate your Implementation of the JAX-WS SEI (Service Interface)
    4. Instantiate a EndpointImpl with the SpringBus and SEI implementing Beans
    5. Call publish() method on that EndpointImpl

    Done.

    @SpringBootApplication
    public class SimpleBootCxfApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(SimpleBootCxfApplication.class, args);
        }
    
        @Bean
        public ServletRegistrationBean dispatcherServlet() {
            return new ServletRegistrationBean(new CXFServlet(), "/soap-api/*");
        }
    
        @Bean(name = Bus.DEFAULT_BUS_ID)
        public SpringBus springBus() {
            return new SpringBus();
        }    
    
        @Bean
        public WeatherService weatherService() {
            return new WeatherServiceEndpoint();
        }
    
        @Bean
        public Endpoint endpoint() {
            EndpointImpl endpoint = new EndpointImpl(springBus(), weatherService());
            endpoint.publish("/WeatherSoapService");
            return endpoint;
        }
    }
    

提交回复
热议问题