2021-11-24 10:45:15,633 INFO [restartedMain] o.s.i.m.i.MqttPahoMessageDrivenChannelAdapter [LogAccessor.java : 292] started bean 'inbound'; defined in: 'class path resource [com/yaken/config/MqttConfig.class]'; from source: 'com.yaken.config.MqttConfig.inbound()'
2021-11-24 10:45:15,639 INFO [restartedMain] io.undertow [Undertow.java : 120] starting server: Undertow - 2.2.12.Final
2021-11-24 10:45:15,646 INFO [restartedMain] org.xnio [Xnio.java : 95] XNIO version 3.8.4.Final
2021-11-24 10:45:15,655 INFO [restartedMain] org.xnio.nio [NioXnio.java : 58] XNIO NIO Implementation Version 3.8.4.Final
2021-11-24 10:45:15,724 INFO [restartedMain] org.jboss.threads [Version.java : 52] JBoss Threads version 3.1.0.Final
2021-11-24 10:45:15,767 INFO [restartedMain] o.s.b.w.e.undertow.UndertowWebServer [UndertowWebServer.java : 119] Undertow started on port(s) 8888 (http)
2021-11-24 10:45:15,772 WARN [restartedMain] o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext [AbstractApplicationContext.java : 591] Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException: Cannot invoke "org.springframework.web.servlet.mvc.condition.PatternsRequestCondition.getPatterns()" because "this.condition" is null
2021-11-24 10:45:15,772 INFO [restartedMain] o.s.i.endpoint.EventDrivenConsumer [LogAccessor.java : 174] Removing {logging-channel-adapter:_org.springframework.integration.errorLogger} as a subscriber to the 'errorChannel' channel
2021-11-24 10:45:15,773 INFO [restartedMain] o.s.i.c.PublishSubscribeChannel [LogAccessor.java : 174] Channel 'yaken.errorChannel' has 0 subscriber(s).
2021-11-24 10:45:15,773 INFO [restartedMain] o.s.i.endpoint.EventDrivenConsumer [LogAccessor.java : 292] stopped bean '_org.springframework.integration.errorLogger'
2021-11-24 10:45:19,784 ERROR [MQTT Ping: 1133363739727241217_inbound] o.e.p.c.mqttv3.internal.ClientState [JSR47Logger.java : 210] 1133363739727241217_inbound: Timed out as no activity, keepAlive=2,000,000,000 lastOutboundActivity=86,592,399,738,807 lastInboundActivity=86,590,398,064,634 time=86,594,402,071,285 lastPing=86,592,399,744,206
2021-11-24 10:45:19,786 INFO [restartedMain] o.s.i.m.i.MqttPahoMessageDrivenChannelAdapter [LogAccessor.java : 292] stopped bean 'inbound'; defined in: 'class path resource [com/yaken/config/MqttConfig.class]'; from source: 'com.yaken.config.MqttConfig.inbound()'
2021-11-24 10:45:19,793 INFO [restartedMain] o.s.i.g.GatewayProxyFactoryBean$MethodInvocationGateway [LogAccessor.java : 292] stopped bean 'mqttGateway#sendToMqtt(String, String)'
2021-11-24 10:45:19,793 INFO [restartedMain] o.s.i.g.GatewayProxyFactoryBean [LogAccessor.java : 292] stopped bean 'mqttGateway'
2021-11-24 10:45:19,802 INFO [restartedMain] io.undertow [Undertow.java : 259] stopping server: Undertow - 2.2.12.Final
2021-11-24 10:45:19,824 INFO [restartedMain] o.s.b.a.l.ConditionEvaluationReportLoggingListener [ConditionEvaluationReportLoggingListener.java : 136]
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-11-24 10:45:19,845 ERROR [restartedMain] o.s.boot.SpringApplication [SpringApplication.java : 819] Application run failed
org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException: Cannot invoke "org.springframework.web.servlet.mvc.condition.PatternsRequestCondition.getPatterns()" because "this.condition" is null
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:181)
at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:54)
at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:356)
at java.base/java.lang.Iterable.forEach(Iterable.java:75)
at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:155)
at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:123)
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:935)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:586)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:730)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:412)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:302)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1290)
at com.yaken.YakenApplication.main(YakenApplication.java:24)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: java.lang.NullPointerException: Cannot invoke "org.springframework.web.servlet.mvc.condition.PatternsRequestCondition.getPatterns()" because "this.condition" is null
at springfox.documentation.spring.web.WebMvcPatternsRequestConditionWrapper.getPatterns(WebMvcPatternsRequestConditionWrapper.java:56)
at springfox.documentation.RequestHandler.sortedPaths(RequestHandler.java:113)
at springfox.documentation.spi.service.contexts.Orderings.lambda$byPatternsCondition$3(Orderings.java:89)
at java.base/java.util.Comparator.lambda$comparing$77a9974f$1(Comparator.java:473)
at java.base/java.util.TimSort.countRunAndMakeAscending(TimSort.java:355)
at java.base/java.util.TimSort.sort(TimSort.java:234)
at java.base/java.util.Arrays.sort(Arrays.java:1307)
at java.base/java.util.ArrayList.sort(ArrayList.java:1721)
at java.base/java.util.stream.SortedOps$RefSortingSink.end(SortedOps.java:392)
at java.base/java.util.stream.Sink$ChainedReference.end(Sink.java:258)
at java.base/java.util.stream.Sink$ChainedReference.end(Sink.java:258)
at java.base/java.util.stream.Sink$ChainedReference.end(Sink.java:258)
at java.base/java.util.stream.Sink$ChainedReference.end(Sink.java:258)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:510)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
at springfox.documentation.spring.web.plugins.WebMvcRequestHandlerProvider.requestHandlers(WebMvcRequestHandlerProvider.java:81)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
at springfox.documentation.spring.web.plugins.AbstractDocumentationPluginsBootstrapper.withDefaults(AbstractDocumentationPluginsBootstrapper.java:107)
at springfox.documentation.spring.web.plugins.AbstractDocumentationPluginsBootstrapper.buildContext(AbstractDocumentationPluginsBootstrapper.java:91)
at springfox.documentation.spring.web.plugins.AbstractDocumentationPluginsBootstrapper.bootstrapDocumentationPlugins(AbstractDocumentationPluginsBootstrapper.java:82)
at springfox.documentation.spring.web.plugins.DocumentationPluginsBootstrapper.start(DocumentationPluginsBootstrapper.java:100)
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:178)
... 19 common frames omitted
[spring-projects/spring-boot]因为“this.condition”为空
回答
springboot 2.5.7 就可以了
这是一个 springfox 问题,应该针对相关项目进行报告。另请参阅https://github.com/spring-projects/spring-boot/issues/28769
https://github.com/springfox/springfox/issues/3462已经在 Springfox 端跟踪这一点。
当心:
2021-11-24 10:45:19,784 ERROR [MQTT Ping: 1133363739727241217_inbound] o.e.p.c.mqttv3.internal.ClientState [JSR47Logger.java : 210] 1133363739727241217_inbound: Timed out as no activity, keepAlive=2,000,000,000 lastOutboundActivity=86,592,399,738,807 lastInboundActivity=86,590,398,064,634 time=86,594,402,071,285 lastPing=86,592,399,744,206
不是因为springfox,我使用mqtt有问题
@weir2010 您能否为您的评论提供更多背景信息?我没有看到 MQTT 和 Web 请求路径解析之间的联系。
关键代码:
package com.yaken.config;
import java.util.Arrays;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.integration.annotation.IntegrationComponentScan;
import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.integration.core.MessageProducer;
import org.springframework.integration.mqtt.core.DefaultMqttPahoClientFactory;
import org.springframework.integration.mqtt.core.MqttPahoClientFactory;
import org.springframework.integration.mqtt.inbound.MqttPahoMessageDrivenChannelAdapter;
import org.springframework.integration.mqtt.outbound.MqttPahoMessageHandler;
import org.springframework.integration.mqtt.support.DefaultPahoMessageConverter;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.MessageHandler;
import org.springframework.messaging.MessagingException;
import com.yaken.mqtt.MqttReceiveService;
import lombok.extern.slf4j.Slf4j;
/**
* MQTT接收消息处理
*
* @author weir
*
* 2019年6月16日 下午2:41:45
*/
@Slf4j
@Configuration
@IntegrationComponentScan
public class MqttConfig {
private static final String MQTT_RECEIVEDTOPIC = "mqtt_receivedTopic";
private static final String SP_INBOUND = "_inbound";
private MqttPahoMessageDrivenChannelAdapter adapter;
@Value("${mqtt.username}")
private String username;
@Value("${mqtt.pwd}")
private String password;
@Value("${mqtt.url}")
private String hostUrl;
@Value("${mqtt.client.id}")
private String clientId;
@Value("${mqtt.default.topic}")
private String defaultTopic;
@Value("${mqtt.completionTimeout}")
private int completionTimeout;
@Autowired
private MqttReceiveService mqttReceiveService;
@Bean
public MqttConnectOptions getMqttConnectOptions() {
MqttConnectOptions mqttConnectOptions = new MqttConnectOptions();
mqttConnectOptions.setUserName(username);
mqttConnectOptions.setPassword(password.toCharArray());
mqttConnectOptions.setServerURIs(new String[] { hostUrl });
mqttConnectOptions.setKeepAliveInterval(2); // 设置会话心跳时间
return mqttConnectOptions;
}
@Bean
public MqttPahoClientFactory mqttClientFactory() {
DefaultMqttPahoClientFactory factory = new DefaultMqttPahoClientFactory();
factory.setConnectionOptions(getMqttConnectOptions());
return factory;
}
@Bean
@ServiceActivator(inputChannel = "mqttOutboundChannel")
public MessageHandler mqttOutbound() {
MqttPahoMessageHandler messageHandler = new MqttPahoMessageHandler(clientId, mqttClientFactory());
messageHandler.setAsync(true);
messageHandler.setDefaultTopic(defaultTopic);
return messageHandler;
}
@Bean
public MessageChannel mqttOutboundChannel() {
return new DirectChannel();
}
/**
* 接收通道
*
* @return MessageChannel
*/
@Bean
public MessageChannel mqttInputChannel() {
return new DirectChannel();
}
/**
* 配置client,监听的topic
*
* @return MessageProducer
*/
@Bean
public MessageProducer inbound() {
adapter = new MqttPahoMessageDrivenChannelAdapter(clientId + SP_INBOUND, mqttClientFactory(), defaultTopic);
adapter.setCompletionTimeout(completionTimeout);
adapter.setConverter(new DefaultPahoMessageConverter());
adapter.setOutputChannel(mqttInputChannel());
return adapter;
}
}
@weir2010 目前还不清楚您在上面的评论中提供的示例代码如何与您最初发布的堆栈跟踪相关。如果您认为这是 Spring Boot 问题,请提供一个示例应用程序(作为 github 项目的 zip 文件),该应用程序可重现该问题并且不包含 springfox 作为依赖项。
我发现了问题。真的很招摇ok
我对最新的 Spring 版本 2.6.1 和 springfox-swagger2 版本 3.0.0 也有同样的问题。有解决方法吗?
与上面提到的同样的问题
任何更新?有计划发布固定版本吗?
请在发表评论之前阅读问题历史记录。这是 springfox 的问题,我们在这里无能为力。
要解决此问题,您可以添加@EnableWebMvc
到 spring-context。你需要禁用测试,@Profile(!test) @EnableWebMvc
这将使您能够解决该问题。
感谢您尝试提供帮助,@mert-unsal。不幸的是,这几乎肯定会产生额外的不良影响,因为它将禁用 Spring Boot 的所有 Spring MVC 自动配置。
` 包 com.miniprojecttwo.productservice.config;
导入 org.springframework.beans.factory.InitializingBean;导入 org.springframework.context.annotation.Bean;导入 org.springframework.context.annotation.Configuration;导入 org.springframework.web.servlet.mvc.method.RequestMappingInfo;导入 org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping;导入 springfox.documentation.builders.PathSelectors;导入 springfox.documentation.builders.RequestHandlerSelectors;导入 springfox.documentation.service.*;导入 springfox.documentation.spi.DocumentationType;导入 springfox.documentation.spi.service.RequestHandlerProvider;导入 springfox.documentation.spi.service.contexts.SecurityContext;导入 springfox.documentation.spring.web.WebMvcRequestHandler;导入 springfox.documentation.spring.web.paths.Paths;导入 springfox.documentation.spring.web.plugins.Docket;导入 springfox.documentation.spring.web.plugins.DocumentationPluginsBootstrapper;导入 springfox.documentation.spring.web.plugins.WebMvcRequestHandlerProvider;导入 springfox.documentation.spring.web.readers.operation.HandlerMethodResolver;
导入 javax.servlet.ServletContext;导入 java.util.*;导入java.util.stream.Collectors;
导入静态java.util.stream.Collectors.toList;导入静态 springfox.documentation.RequestHandler.byPatternsCondition;
@Configuration 公共类 SwaggerConfiguration {
public static final String AUTHORIZATION_HEADER = "授权";
private ApiInfo apiInfo() { return new ApiInfo("我的 REST API", "API 的一些自定义描述。", "1.0", "服务条款", new Contact("Sallo Szrajbman", "www.baeldung.com" , "salloszraj@gmail.com"), "API 许可证", "API 许可证 URL", Collections.emptyList()); }
@Bean public Docket api() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .securityContexts(Arrays.asList(securityContext())) .securitySchemes(Arrays.asList(apiKey())) .select( ) .apis(RequestHandlerSelectors.any()) .paths(PathSelectors.any()) .build(); }
private ApiKey apiKey() { return new ApiKey("Bearer", AUTHORIZATION_HEADER, "header"); }
私有 SecurityContext securityContext() { return SecurityContext.builder() .securityReferences(defaultAuth()) .build(); }
列表
@Bean public InitializingBean removeSpringfoxHandlerProvider(DocumentationPluginsBootstrapper bootstrapper) { return () -> bootstrapper.getHandlerProviders().removeIf(WebMvcRequestHandlerProvider.class::isInstance); } }
@Bean public RequestHandlerProvider customRequestHandlerProvider(可选
RequestMappingInfo adjustmentInfo(RequestMappingInfo info) { if (info.getPathPatternsCondition() == null) return info; } String[] 模式 = info.getPathPatternsCondition().getPatternValues().toArray(String[]::new); return info.mutate().options(new RequestMappingInfo.BuilderConfiguration()).paths(patterns).build(); } }
`
我解决了 Spring Boot 2.5.12
您可以在驱动器 SQL (POSTGRES) 中安装 JAR,直接退出 pom 项目并聚合构建路径和编译。