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

10 篇文章 0 订阅
7 篇文章 0 订阅


@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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在Spring Boot中实现Web服务接口可以通过以下步骤进行: 1. 添加依赖:在`pom.xml`文件中添加以下依赖: ```xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web-services</artifactId> </dependency> ``` 2. 创建接口:创建一个接口来定义Web服务的操作。例如,创建一个名为`HelloWorldService`的接口,并在其中定义一个`sayHello`方法: ```java @WebService public interface HelloWorldService { @WebMethod String sayHello(String name); } ``` 3. 实现接口:创建一个实现接口的类,并在其中实现接口中定义的方法。例如,创建一个名为`HelloWorldServiceImpl`的类: ```java @Service @WebService(endpointInterface = "com.example.HelloWorldService") public class HelloWorldServiceImpl implements HelloWorldService { @Override public String sayHello(String name) { return "Hello, " + name + "!"; } } ``` 4. 配置WebService:在`application.properties`文件中添加以下配置: ```properties # 指定WebService的路径 spring.webservices.path=/webService/ws ``` 5. 启动应用程序:创建一个Spring Boot应用程序,并在`main`方法中启动它: ```java @SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } } ``` 现在,您已经成功地在Spring Boot中实现了一个简单的Web服务接口。您可以使用Java客户端或通过访问`http://localhost:8080/webService/ws/api?wsdl`来测试该接口
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值