Closed weir2010 closed 2 years ago
springboot 2.5.7 is ok
This is a springfox problem that should be reported against the relevant project. See also https://github.com/spring-projects/spring-boot/issues/28769
https://github.com/springfox/springfox/issues/3462 is already tracking this on the Springfox side.
be careful:
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
Not because springfox ,I have a problem using mqtt
@weir2010 Can you please provide some more context for your comment? I don't see the connection between MQTT and web request path parsing.
critical code:
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 It's still not clear how the sample code you've provided in the comment above relates to the stacktrace that you initially posted. If you believe that this is a Spring Boot issue please provide a sample application that (as a zip file for github project) that reproduces the issue and doesn't have springfox as a dependency.
I found the problem. It's really swagger ok
I have the same problem with the newest Spring version 2.6.1 and springfox-swagger2 version 3.0.0 . Is there a workaround?
same problem as mentioned above
Any update? Any plans to release a fixed version?
Please read the issue history before commenting. This is a springfox issue and nothing we can do here.
To work around this problem, you can add @EnableWebMvc
to spring-context. You are gonna need to disable on testing, @Profile(!test) @EnableWebMvc
This will let you work around the problem.
Thanks for trying to help, @mert-unsal. Unfortunately, that's almost certainly going to have additional unwanted effects as it will disable all of Spring Boot's auto-configuration of Spring MVC.
` package com.miniprojecttwo.productservice.config;
import org.springframework.beans.factory.InitializingBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.mvc.method.RequestMappingInfo; import org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping; import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.service.*; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spi.service.RequestHandlerProvider; import springfox.documentation.spi.service.contexts.SecurityContext; import springfox.documentation.spring.web.WebMvcRequestHandler; import springfox.documentation.spring.web.paths.Paths; import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.spring.web.plugins.DocumentationPluginsBootstrapper; import springfox.documentation.spring.web.plugins.WebMvcRequestHandlerProvider; import springfox.documentation.spring.web.readers.operation.HandlerMethodResolver;
import javax.servlet.ServletContext; import java.util.*; import java.util.stream.Collectors;
import static java.util.stream.Collectors.toList; import static springfox.documentation.RequestHandler.byPatternsCondition;
@Configuration public class SwaggerConfiguration {
public static final String AUTHORIZATION_HEADER = "Authorization";
private ApiInfo apiInfo() { return new ApiInfo("My REST API", "Some custom description of API.", "1.0", "Terms of service", new Contact("Sallo Szrajbman", "www.baeldung.com", "salloszraj@gmail.com"), "License of API", "API license 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"); }
private SecurityContext securityContext() { return SecurityContext.builder() .securityReferences(defaultAuth()) .build(); }
List
@Bean public InitializingBean removeSpringfoxHandlerProvider(DocumentationPluginsBootstrapper bootstrapper) { return () -> bootstrapper.getHandlerProviders().removeIf(WebMvcRequestHandlerProvider.class::isInstance); }
@Bean
public RequestHandlerProvider customRequestHandlerProvider(Optional
RequestMappingInfo tweakInfo(RequestMappingInfo info) { if (info.getPathPatternsCondition() == null) return info; String[] patterns = info.getPathPatternsCondition().getPatternValues().toArray(String[]::new); return info.mutate().options(new RequestMappingInfo.BuilderConfiguration()).paths(patterns).build(); } }
`
i resolve with spring boot 2.5.12
Yo lo corregí instalando el JAR de mi drive SQL (POSTGRES) directamente a mi proyecto quitandolo del pom y agregarlos al built path y agregandolo al compilado.
springboot 2.6.0 :