dependency cycle on spring WebSocket interceptor and spring cloud stream -
i trying create websocket interceptor send message using messagechannel spring cloud stream . facing dependency cycle
┌─────┐ | mychannelinterceptor defined in file [/users/shahbour/ideaprojects/proxy/target/classes/com/xxxxx/proxy/broker/mychannelinterceptor.class] ↑ ↓ | com.xxxx.proxy.service.xxxxxbinding (field private java.util.map org.springframework.cloud.stream.binding.bindableproxyfactory.bindingtargetfactories) ↑ ↓ | org.springframework.cloud.stream.config.bindingserviceconfiguration (field private java.util.list org.springframework.cloud.stream.config.bindingserviceconfiguration.custommessageconverters) ↑ ↓ | org.springframework.web.socket.config.annotation.delegatingwebsocketmessagebrokerconfiguration ↑ ↓ | websocketconfig defined in file [/users/shahbour/ideaprojects/proxy/target/classes/com/xxxx/proxy/config/websocketconfig.class] └─────┘
my problem need inject messagechannel websocket interceptor
i receiving below error if use @autowire
org.springframework.context.applicationcontextexception: failed start bean 'subprotocolwebsockethandler'; nested exception java.lang.illegalargumentexception: no handlers @ org.springframework.context.support.defaultlifecycleprocessor.dostart(defaultlifecycleprocessor.java:178) ~[spring-context-4.3.7.release.jar:4.3.7.release] @ org.springframework.context.support.defaultlifecycleprocessor.dostart(defaultlifecycleprocessor.java:167) ~[spring-context-4.3.7.release.jar:4.3.7.release] @ org.springframework.context.support.defaultlifecycleprocessor.access$200(defaultlifecycleprocessor.java:50) ~[spring-context-4.3.7.release.jar:4.3.7.release] @ org.springframework.context.support.defaultlifecycleprocessor$lifecyclegroup.start(defaultlifecycleprocessor.java:348) ~[spring-context-4.3.7.release.jar:4.3.7.release] @ org.springframework.context.support.defaultlifecycleprocessor.startbeans(defaultlifecycleprocessor.java:151) ~[spring-context-4.3.7.release.jar:4.3.7.release] @ org.springframework.context.support.defaultlifecycleprocessor.onrefresh(defaultlifecycleprocessor.java:114) ~[spring-context-4.3.7.release.jar:4.3.7.release] @ org.springframework.context.support.abstractapplicationcontext.finishrefresh(abstractapplicationcontext.java:879) ~[spring-context-4.3.7.release.jar:4.3.7.release] @ org.springframework.boot.context.embedded.embeddedwebapplicationcontext.finishrefresh(embeddedwebapplicationcontext.java:144) ~[spring-boot-1.5.2.release.jar:1.5.2.release] @ org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:545) ~[spring-context-4.3.7.release.jar:4.3.7.release] @ org.springframework.boot.context.embedded.embeddedwebapplicationcontext.refresh(embeddedwebapplicationcontext.java:122) ~[spring-boot-1.5.2.release.jar:1.5.2.release] @ org.springframework.boot.springapplication.refresh(springapplication.java:737) [spring-boot-1.5.2.release.jar:1.5.2.release] @ org.springframework.boot.springapplication.refreshcontext(springapplication.java:370) [spring-boot-1.5.2.release.jar:1.5.2.release] @ org.springframework.boot.springapplication.run(springapplication.java:314) [spring-boot-1.5.2.release.jar:1.5.2.release] @ org.springframework.boot.springapplication.run(springapplication.java:1162) [spring-boot-1.5.2.release.jar:1.5.2.release] @ org.springframework.boot.springapplication.run(springapplication.java:1151) [spring-boot-1.5.2.release.jar:1.5.2.release] @ com.xxxx.proxy.xxxxxxproxyapplication.main(xxxxxproxyapplication.java:29) [classes/:na] caused by: java.lang.illegalargumentexception: no handlers @ org.springframework.util.assert.istrue(assert.java:92) ~[spring-core-4.3.7.release.jar:4.3.7.release] @ org.springframework.web.socket.messaging.subprotocolwebsockethandler.start(subprotocolwebsockethandler.java:244) ~[spring-websocket-4.3.7.release.jar:4.3.7.release] @ org.springframework.context.support.defaultlifecycleprocessor.dostart(defaultlifecycleprocessor.java:175) ~[spring-context-4.3.7.release.jar:4.3.7.release] ... 15 common frames omitted
ok. thank you! no see problem.
look:
- your
mychannelinterceptor
depends on auto-created channelbinderservice
. - that 1 tries infer
messageconverter
s application context. - the
abstractmessagebrokerconfiguration
provides 1 in face ofcompositemessageconverter brokermessageconverter
- that class instantiated
@enablewebsocketmessagebroker
- which, in turn, scans
websocketconfig
because ofabstractwebsocketmessagebrokerconfigurer
- and last 1 wants
mychannelinterceptor
injected.
not sure how fix out-of-the-box feature, here kind of workaround:
public class mychannelinterceptor extends channelinterceptoradapter { @autowired private messagechannel output;
@configuration public class websocketconfig extends abstractwebsocketmessagebrokerconfigurer { @bean public mychannelinterceptor mychannelinterceptor() { return new mychannelinterceptor(); } ... @override public void configureclientinboundchannel(channelregistration registration) { registration.setinterceptors(mychannelinterceptor()); }
Comments
Post a Comment