如何在客户端配置WebSocketTransportRegistration? BeanCurrentlyInCreationException

时间:2017-07-10 11:51:42

标签: java websocket stomp sockjs spring-messaging

我有通过网络套接字进行交互的服务器和客户端应用程序。

有关客户端应用配置的问题 我有以下配置:

 @Override
    public void configureMessageBroker(MessageBrokerRegistry config) {
        config.enableSimpleBroker("/topic", "/queue");
        config.setUserDestinationPrefix("/user");
        config.setApplicationDestinationPrefixes("/app");
    }

    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        registry.addEndpoint("/ws").withSockJS()
                .setStreamBytesLimit(Integer.MAX_VALUE)
                .setHttpMessageCacheSize(Integer.MAX_VALUE);
    }

    @Bean
    public WebSocketStompClient getClient() {
        logger.debug("getClient invoked");
        List<Transport> transports = new ArrayList<>();
        transports.add(new WebSocketTransport(new StandardWebSocketClient()));
        WebSocketClient webSocketClient = new SockJsClient(transports);
        WebSocketStompClient stompClient = new WebSocketStompClient(webSocketClient);
        stompClient.setMessageConverter(new MappingJackson2MessageConverter());
        stompClient.setInboundMessageSizeLimit(Integer.MAX_VALUE);
        return stompClient;
    }

    @Bean
    public ServletServerContainerFactoryBean createServletServerContainerFactoryBean() {
        ServletServerContainerFactoryBean container = new ServletServerContainerFactoryBean();
        container.setMaxTextMessageBufferSize(Integer.MAX_VALUE / 1000);
        container.setMaxBinaryMessageBufferSize(Integer.MAX_VALUE / 1000);
        logger.info("Websocket factory returned");
        return container;
    }

但在调试中我看到调用构造函数时:org.springframework.web.socket.config.annotation.WebMvcStompEndpointRegistry#WebMvcStompEndpointRegistry

if (transportRegistration.getMessageSizeLimit() != null) {
            this.stompHandler.setMessageSizeLimit(transportRegistration.getMessageSizeLimit());
        }

这种情况是错误的。

我也试着写:

@Bean
    public WebSocketTransportRegistration getRegistration(WebSocketTransportRegistration registration) {
        logger.debug("getRegistration invoked");
        registration.setSendBufferSizeLimit(Integer.MAX_VALUE);
        registration.setMessageSizeLimit(Integer.MAX_VALUE);
        registration.setSendTimeLimit(Integer.MAX_VALUE);
        registration.setSendTimeLimit(60 * 1000);
        return registration;
    }

但它导致以下错误:

2017-07-10 14:44:08,930 DEBUG org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter.report:38 - Application failed to start due to an exception
org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'getRegistration': Requested bean is currently in creation: Is there an unresolvable circular reference?
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.beforeSingletonCreation(DefaultSingletonBeanRegistry.java:347)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
    at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:208)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066)
    at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:835)
    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:467)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1173)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1067)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:314)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151)
    at com.***.BankApplication.main(BankApplication.java:19)
2017-07-10 14:44:08,930 ERROR org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter.report:42 - 

***************************
APPLICATION FAILED TO START
***************************

Description:

The dependencies of some of the beans in the application context form a cycle:

┌─────┐
|  getRegistration defined in class path resource [com/***/config/AppWebSocketConfigurer.class]
└─────┘

如何在客户端配置WebSocketTransportRegistration?

0 个答案:

没有答案