Spring Swagger2集成ServletContext自动装配问题(Spring Swagger2 integration ServletContext autowiring issue)
我正在使用嵌入式Jetty 9运行Spring 4 mvc。我试图插入Swagger2工具,但我遇到了下一个异常
Error creating bean with name 'documentationPluginsBootstrapper'
这个例外的根本原因是
nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [javax.servlet.ServletContext] found for dependency [javax.servlet.ServletContext]: expected at least 1 bean which qualifies as autowire candidate for this dependency.
这是我的SwaggerConfigClass
@Configuration @EnableSwagger2 public class SwaggerConfig { private static final Logger logger = Logger.getLogger(SwaggerConfig.class); @Bean public Docket api() { return new Docket(DocumentationType.SWAGGER_2) .select() .apis(RequestHandlerSelectors.any()) .paths(PathSelectors.any()) .build() .apiInfo(apiInfo()); } private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("TITLE") .description("DESCRIPTION") .version("VERSION") .termsOfServiceUrl("http://terms-of-services.url") .license("LICENSE") .licenseUrl("http://url-to-license.com") .build(); } }
之后我创建了工厂类
public class ServletContextFactory implements FactoryBean<ServletContext>, ServletContextAware { private ServletContext servletContext; @Override public ServletContext getObject() throws Exception { return servletContext; } @Override public Class<?> getObjectType() { return ServletContext.class; } @Override public boolean isSingleton() { return true; } @Override public void setServletContext(ServletContext servletContext) { this.servletContext = servletContext; } }
然后在重新声明的bean中手动使用它
@Bean public DocumentationPluginsBootstrapper documentationPluginsBootstrapper(DocumentationPluginsManager documentationPluginsManager, List<RequestHandlerProvider> handlerProviders, DocumentationCache scanned, ApiDocumentationScanner resourceListing, TypeResolver typeResolver, Defaults defaults) throws Exception { return new DocumentationPluginsBootstrapper(documentationPluginsManager, handlerProviders, scanned, resourceListing, typeResolver, defaults, new ServletContextFactory().getObject()); }
但仍然有一个异常(另一个例外)NullPointerException作为下一个
Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException
那么有人可以建议一些这种自动装配问题的解决方案吗?
I'm running Spring 4 mvc with embedded Jetty 9. I tried to plug in Swagger2 tool, but I faced next exception
Error creating bean with name 'documentationPluginsBootstrapper'
the root cause of this exception is
nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [javax.servlet.ServletContext] found for dependency [javax.servlet.ServletContext]: expected at least 1 bean which qualifies as autowire candidate for this dependency.
This is my SwaggerConfigClass
@Configuration @EnableSwagger2 public class SwaggerConfig { private static final Logger logger = Logger.getLogger(SwaggerConfig.class); @Bean public Docket api() { return new Docket(DocumentationType.SWAGGER_2) .select() .apis(RequestHandlerSelectors.any()) .paths(PathSelectors.any()) .build() .apiInfo(apiInfo()); } private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("TITLE") .description("DESCRIPTION") .version("VERSION") .termsOfServiceUrl("http://terms-of-services.url") .license("LICENSE") .licenseUrl("http://url-to-license.com") .build(); } }
After that I created factory class
public class ServletContextFactory implements FactoryBean<ServletContext>, ServletContextAware { private ServletContext servletContext; @Override public ServletContext getObject() throws Exception { return servletContext; } @Override public Class<?> getObjectType() { return ServletContext.class; } @Override public boolean isSingleton() { return true; } @Override public void setServletContext(ServletContext servletContext) { this.servletContext = servletContext; } }
and then manually used it in redeclared bean
@Bean public DocumentationPluginsBootstrapper documentationPluginsBootstrapper(DocumentationPluginsManager documentationPluginsManager, List<RequestHandlerProvider> handlerProviders, DocumentationCache scanned, ApiDocumentationScanner resourceListing, TypeResolver typeResolver, Defaults defaults) throws Exception { return new DocumentationPluginsBootstrapper(documentationPluginsManager, handlerProviders, scanned, resourceListing, typeResolver, defaults, new ServletContextFactory().getObject()); }
but still had an exception (another exception) NullPointerException as next
Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException
So can anyone suggest some solution of this autowiring problem?
原文:https://stackoverflow.com/questions/44567619
满意答案
Paramiko默认不输出任何内容。 您可能调用了日志记录模块,设置了当paramiko设置自己的日志记录时继承的日志级别。
如果您想要访问paramiko logger来覆盖设置:
logger = paramiko.util.logging.getLogger()
还有一个便利功能,可以将所有内容记录到文件中:
paramiko.util.log_to_file('filename.log')
Paramiko doesn't output anything by default. You probably have a call to the logging module, setting a loglevel that's inherited when paramiko sets up it's own logging.
If you want to get at the paramiko logger to override the settings:
logger = paramiko.util.logging.getLogger()
There's also a convenience function to log everything to a file:
paramiko.util.log_to_file('filename.log')
相关问答
更多windows下paramiko sshclient远程登录到linux机器的交互问题
paramiko的sshclient与sftp(paramiko's sshclient with sftp)
无法使用Paramiko远程执行tcpdump(Unable to execute tcpdump remotely with Paramiko)
Python的paramiko模块使用多个命令(Python paramiko module using multiple commands)
paramiko SSHClient连接卡住了(paramiko SSHClient connect stuck)
Paramiko在读取所有输出之前完成处理(Paramiko finish process before reading all output)
转义paramiko.SSHClient()。exec_command的参数(Escape arguments for paramiko.SSHClient().exec_command)
增加paramiko.SSHClient.exec_command()宽度(increase paramiko.SSHClient.exec_command() width)
Paramiko Buffer问题(Paramiko Buffer issue)
抑制Paramiko SSHClient类的输出(Suppressing Output of Paramiko SSHClient Class)
相关文章
更多springboot整合Swagger2
使用spring-integration-kafka操作kafka
Spring MVC 3 深入总结
Swagger UI 快速入门-springmvc 整合Swagger UI 教程
最新问答
更多获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
如何通过引用返回对象?(How is returning an object by reference possible?)
矩阵如何存储在内存中?(How are matrices stored in memory?)
每个请求的Java新会话?(Java New Session For Each Request?)
css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
xcode语法颜色编码解释?(xcode syntax color coding explained?)
在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!