zyro23 / grails-spring-websocket

93 stars 28 forks source link

Custom configuration not work #61

Closed mfvitale closed 6 years ago

mfvitale commented 6 years ago

Hi,

i have followed the guide for adding custom websocket configuration but on startup i get this error

15:41:14.971 [main] ERROR - Line 838 in o.s.boot.SpringApplication - Application startup failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'webSocketMessageBrokerStats' defined in class path resource [org/springframework/web/socket/config/annotation/DelegatingWebSocketMessageBrokerConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.socket.config.WebSocketMessageBrokerStats]: Factory method 'webSocketMessageBrokerStats' threw exception; nested exception is java.lang.IllegalStateException: ThreadPoolTaskExecutor not initialized at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1123) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1018) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) 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:776) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:861) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:369) at org.springframework.boot.SpringApplication.run(SpringApplication.java:313) at grails.boot.GrailsApp.run(GrailsApp.groovy:55) at grails.boot.GrailsApp.run(GrailsApp.groovy:374) at grails.boot.GrailsApp.run(GrailsApp.groovy:363) at grails.boot.GrailsApp$run.call(Unknown Source) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133) at com.motork.funnelk.Application.main(Application.groovy:12) Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.socket.config.WebSocketMessageBrokerStats]: Factory method 'webSocketMessageBrokerStats' threw exception; nested exception is java.lang.IllegalStateException: ThreadPoolTaskExecutor not initialized at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) ... 23 common frames omitted Caused by: java.lang.IllegalStateException: ThreadPoolTaskExecutor not initialized at org.springframework.util.Assert.state(Assert.java:392) at org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor.getThreadPoolExecutor(ThreadPoolTaskExecutor.java:260) at org.springframework.web.socket.config.WebSocketMessageBrokerStats.setInboundChannelExecutor(WebSocketMessageBrokerStats.java:96) at org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurationSupport.webSocketMessageBrokerStats(WebSocketMessageBrokerConfigurationSupport.java:126) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1426) at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) ... 24 common frames omitted

I am using Grails 3.2.0 with grails-spring-websocket 2.3.0.

Have you any idea/suggestion about that?

Thanks, Mario

zyro23 commented 6 years ago

could #41 be related? i.e. is your custom webSocketConfig bean defined in resources.groovy and subject to ComponentScan at the same time?

if so, one possible solution would be to exclude it from component-scanning and to keep it in resources.groovy (as that is needed to properly override the default webSocketConfig bean provided by the plugin).

how you do that depends on how you defined/activated your component scan.

as an example, if you defined it via the @ComponentScan annotation, you could add an exclude filter:

@ComponentScan(
    basePackages = "my.base.package",
    excludeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = MyCustomWebSocketConfig)
)
mfvitale commented 6 years ago

@zyro23 Perfect! Thank you!