当前位置:   article > 正文

Parameter 0 of method errorPageCustomizer in ErrorMvcAutoConfiguration 异常解决_parameter 0 of method setconfigurers in org.spring

parameter 0 of method setconfigurers in org.springframework.web.servlet.conf

Parameter 0 of method errorPageCustomizer in ErrorMvcAutoConfiguration required a bean of type 'xxx.DispatcherServletPath' that could not be found异常解决

一. 异常问题

我在利用Web Service进行RPC远程接口调用的时候,需要配置注册一个CXFServlet到web容器中,代码如下:

 
  1. package com.yyg.boot.config;
  2. import com.yyg.boot.service.MyService;
  3. import com.yyg.boot.service.impl.MyServiceImpl;
  4. import org.apache.cxf.Bus;
  5. import org.apache.cxf.bus.spring.SpringBus;
  6. import org.apache.cxf.jaxws.EndpointImpl;
  7. import org.apache.cxf.transport.servlet.CXFServlet;
  8. import org.springframework.boot.web.servlet.ServletRegistrationBean;
  9. import org.springframework.context.annotation.Bean;
  10. import org.springframework.context.annotation.Configuration;
  11. import javax.xml.ws.Endpoint;
  12. /**
  13. * @Author 一一哥Sun
  14. * @Date Created in 2020/5/9
  15. * @Description Description
  16. */
  17. @Configuration
  18. public class CxfConfig {
  19. @Bean
  20. public ServletRegistrationBean dispatcherServlet() {
  21. return new ServletRegistrationBean(new CXFServlet(), "/myService/*");
  22. }
  23. @Bean(name = Bus.DEFAULT_BUS_ID)
  24. public SpringBus springBus() {
  25. return new SpringBus();
  26. }
  27. @Bean
  28. public MyService myService() {
  29. return new MyServiceImpl();
  30. }
  31. @Bean
  32. public Endpoint endpoint() {
  33. EndpointImpl endpoint = new EndpointImpl(springBus(), myService());
  34. endpoint.publish("/api");
  35. return endpoint;
  36. }
  37. }

结果产生了如下异常信息:

  1. "C:\Program Files\Java\jdk1.8.0_192\bin\java.exe" -Dvisualvm.id=10230579134500 "-javaagent:E:\JetBrains\IntelliJ IDEA 2018.1.5\lib\idea_rt.jar=51229:E:\JetBrains\IntelliJ IDEA 2018.1.5\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program
  2. ......
  3. ......
  4. . ____ _ __ _ _
  5. /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
  6. ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
  7. \\/ ___)| |_)| | | | | || (_| | ) ) ) )
  8. ' |____| .__|_| |_|_| |_\__, | / / / /
  9. =========|_|==============|___/=/_/_/_/
  10. :: Spring Boot :: (v2.2.5.RELEASE)
  11. ......
  12. ***************************
  13. APPLICATION FAILED TO START
  14. ***************************
  15. Description:
  16. 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.
  17. The following candidates were found but could not be injected:
  18. - Bean method 'dispatcherServletRegistration' in 'DispatcherServletAutoConfiguration.DispatcherServletRegistrationConfiguration' not loaded because DispatcherServlet Registration found non dispatcher servlet dispatcherServlet
  19. Action:
  20. Consider revisiting the entries above or defining a bean of type 'org.springframework.boot.autoconfigure.web.servlet.DispatcherServletPath' in your configuration.
  21. Process finished with exit code 1

二. 原因分析

我们分析一下原因,其实从log信息中仔细看一下,会发现原因如下:

原因就是在DispatcherServlet Registration的注册中找不到需要用的dispatcherServlet!

按理说dispatcherServlet在SpringBoot中会默认创建并注册,这里怎么突然找不到了呢?之前都可以的!而这个错误是在我创建了这个配置类之后产生的,所以说嘛问题是我上面的代码造成的。

3. 问题解决

后来我仔细分析一下,原来是我的类中,默认的配置方法名有问题:

解决办法如下:

很简单,就是把方法名称换一下,随便换成别的名称即可。

  1. package com.yyg.boot.config;
  2. import com.yyg.boot.service.MyService;
  3. import com.yyg.boot.service.impl.MyServiceImpl;
  4. import org.apache.cxf.Bus;
  5. import org.apache.cxf.bus.spring.SpringBus;
  6. import org.apache.cxf.jaxws.EndpointImpl;
  7. import org.apache.cxf.transport.servlet.CXFServlet;
  8. import org.springframework.boot.web.servlet.ServletRegistrationBean;
  9. import org.springframework.context.annotation.Bean;
  10. import org.springframework.context.annotation.Configuration;
  11. import javax.xml.ws.Endpoint;
  12. /**
  13. * @Author 一一哥Sun
  14. * @Date Created in 2020/5/9
  15. * @Description Description
  16. */
  17. @Configuration
  18. public class CxfConfig {
  19. //注意:该方法的名称不能使用dispatcherServlet(),否则会导致ErrorMvcAutoConfiguration错误.
  20. //org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration
  21. //required a bean of type 'org.springframework.boot.autoconfigure.web.servlet.DispatcherServletPath'
  22. // that could not be found.
  23. // @Bean
  24. // public ServletRegistrationBean dispatcherServlet() {
  25. // return new ServletRegistrationBean(new CXFServlet(), "/myService/*");
  26. // }
  27. @Bean
  28. public ServletRegistrationBean createServletRegistrationBean() {
  29. return new ServletRegistrationBean(new CXFServlet(), "/myService/*");
  30. }
  31. @Bean(name = Bus.DEFAULT_BUS_ID)
  32. public SpringBus springBus() {
  33. return new SpringBus();
  34. }
  35. @Bean
  36. public MyService myService() {
  37. return new MyServiceImpl();
  38. }
  39. @Bean
  40. public Endpoint endpoint() {
  41. EndpointImpl endpoint = new EndpointImpl(springBus(), myService());
  42. endpoint.publish("/api");
  43. return endpoint;
  44. }
  45. }

 

 

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/576375
推荐阅读
相关标签
  

闽ICP备14008679号