如何在WebSocketMessageBrokerStats中将loggingPeriod设置为减小值(默认值为30')
WebSocketMessageBrokerStats由中的@Bean加载
版本:Spring 4.2.0.RELEASE
我当前的配置:
@Configuration
@EnableWebSocketMessageBroker
@EnableScheduling
public class AppWebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
@Override
public void configureMessageBroker(final MessageBrokerRegistry config) {
config.enableSimpleBroker("/topic");
}
@Override
public void registerStompEndpoints(final StompEndpointRegistry registry) {
registry.addEndpoint("/entry")
.setAllowedOrigins("*")
.withSockJS()
.setDisconnectDelay(10000);
}
}
最佳答案
根据WebSocketMessageBrokerStats javadoc:
上述配置通过名称“ webSocketMessageBrokerStats”将该类声明为Spring Bean。
因此,您可以将其添加到配置类中:
@Autowired
private WebSocketMessageBrokerStats webSocketMessageBrokerStats;
@PostConstruct
public void init() {
webSocketMessageBrokerStats.setLoggingPeriod(10 * 1000); // desired time in millis
}