springboot webservice发布成功 项目其他http接口无法访问


@Configuration
public class CxfConfig {
 
    @Bean
    public ServletRegistrationBean ctxServlet() {
        return new ServletRegistrationBean(new CXFServlet(), "/demo/*");
    }
 
    @Bean(name = Bus.DEFAULT_BUS_ID)
    public SpringBus springBus() {
        return new SpringBus();
    }
 
    @Bean
    public DemoService demoService() {
        return new DemoServiceImpl();
    }
 
    @Bean
    public Endpoint endpoint() {
        //绑定要发布的服务
        EndpointImpl endpoint = new EndpointImpl(springBus(), demoService());
        //显示要发布的名称
        endpoint.publish("/api");
        return endpoint;
    }
}
springboot默认注册的是 dispatcherServlet,当手动配置 ServletRegistrationBean后springboot不会再去注册默认的dispatcherServlet,所以需要我们在启动类里手动去注册一个dispatcherServlet。

@Bean
public ServletRegistrationBean dispatcherServlet() {
    AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();
    applicationContext.scan("com.****.manage");
    DispatcherServlet rest_dispatcherServlet = new DispatcherServlet(applicationContext);
    ServletRegistrationBean registrationBean = new ServletRegistrationBean(rest_dispatcherServlet);
    registrationBean.setLoadOnStartup(1);
    registrationBean.addUrlMappings("/*");
    return registrationBean;
}

你可能感兴趣的:(springboot,技术,web)