Springboot创建webService接口时的cxfconfi文件报错出现DispatcherServletPath不能找到

完整错误为

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-07-11 15:37:56.786 ERROR 3176 --- [  restartedMain] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 0 of method errorPageCustomizer in org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration required a bean of type 'org.springframework.boot.autoconfigure.web.servlet.DispatcherServletPath' that could not be found.


Action:

Consider defining a bean of type 'org.springframework.boot.autoconfigure.web.servlet.DispatcherServletPath' in your configuration.


进程已结束,退出代码为 0

org.springframework.boot.autoconfigure.web.servlet.DispatcherServletPath' that could not be found.中可以看出找不到这个方法

代码为:

package com.rc.demo.config;// ~ File Information

import com.rc.demo.webservice.HelloWordImpl;
import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
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 javax.xml.ws.Endpoint;

/**
 * 类说明:webservice发布,默认访问地址为:localhost:8080/services/helloWord?wsdl
 */
@Configuration
public class WebServiceConfig {
 
    // ~ Fields
    @Autowired
    private HelloWordImpl helloWord;//接口实现类
 
    // ~ Methods
    
    /**
     * 此方法作用是改变项目中服务名的前缀名,此处127.0.0.1或者localhost不能访问时,请使用ipconfig查看本机ip来访问
     * 此方法被注释后:wsdl访问地址为http://127.0.0.1:8080/services/user?wsdl
     * 去掉注释后:wsdl访问地址为:http://127.0.0.1:8080/soap/user?wsdl
     * @return
     */
     @SuppressWarnings("all")
     @Bean
     public ServletRegistrationBean dispatcherServlet() {
         return new ServletRegistrationBean(new CXFServlet(), "/soap/*");
     }

    @Bean(name = Bus.DEFAULT_BUS_ID)
    public SpringBus springBus() {
        return new SpringBus();
    }
    
    @Bean
    public Endpoint endpoint() {
        EndpointImpl endpoint=new EndpointImpl(springBus(), helloWord);
        endpoint.publish("/helloWord");//访问地址
        System.out.println("----------------helloWorlWebservice接口启动成功");
        return endpoint;
    }
 
}

我们给

public ServletRegistrationBean dispatcherServlet() {

return new ServletRegistrationBean(new CXFServlet(), "/soap/*");

}

方法名dispathcerServlet改成其他名字就好比如说

public ServletRegistrationBean dispatcherServlet1() {

return new ServletRegistrationBean(new CXFServlet(), "/soap/*");

}

就可以了

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 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、付费专栏及课程。

余额充值