Results 1 to 4 of 4

Thread: org.springframework.flex.messaging.MessageTemplate can't be autowired.

Hybrid View

  1. #1
    Join Date
    Aug 2010
    Posts
    7

    Default org.springframework.flex.messaging.MessageTemplate can't be autowired.

    I am using simple annotations to create a component (@Component) that autowires in the MessageTemplate.

    Assuming the template is defined as follows:

    Code:
        <bean id="messageTemplate" name="messageTemplate" class="org.springframework.flex.messaging.MessageTemplate" >
            <property name="messageBroker" ref="_messageBroker" />
        </bean>
    and the simple component class is


    Code:
    package web.flex;
    
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.flex.messaging.MessageTemplate;
    
    @Component
    public class EventPublisher {
    
        @Autowired
        private MessageTemplate messageTemplate;
    
    }
    The reference for messageTemplate will not autowire as expected; an exception is thrown stating:

    Code:
    org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.flex.messaging.MessageTemplate wmscache.web.flex.EventPublisher.messageTemplate; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.springframework.flex.messaging.MessageTemplate] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

  2. #2
    Join Date
    Apr 2005
    Location
    San Francisco, CA
    Posts
    1,224

    Default

    First off, you shouldn't need to explicitly set the reference to the MessageBroker in the MessageTemplate's bean definition. It should be able to auto-detect it as long as you only have one MessageBroker (which would be typical). I realize this is not explained well enough in the docs and have opened up a Jira for that.

    That said, my suspicion would be that your @Component and the MessageTemplate are defined in two separate ApplicationContexts. For example, if you've got component scanning for the web.flex package turned on in your parent context (i.e., the one loaded by the ContextLoaderListener), but you are defining the MessageBroker and MessageTemplate in a DispatcherServlet context (which is a child context), then the MessageTemplate is not "visible" to the @Component.

    If this is the case, you could either "flatten" everything up into the parent context, or else further tailor your component scanning settings so that components that are specific to the web tier are only picked up by the DispatcherServlet's context.
    Jeremy Grelle

    Staff Engineer, Web Products Team
    SpringSource

  3. #3
    Join Date
    Feb 2009
    Posts
    135

    Default

    Hi,

    I am getting the same error.
    So I moved all my flex related configuration to the main spring/app config file (Nothing in the flex servlet).
    Now I get the below error

    Code:
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.filterChains': Cannot resolve reference to bean 'org.springframework.security.web.DefaultSecurityFilterChain#0' while setting bean property 'sourceList' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.web.DefaultSecurityFilterChain#0': Cannot create inner bean '(inner bean)' of type [org.springframework.security.web.util.AnyRequestMatcher] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.flex.core.EndpointServiceMessagePointcutAdvisor#1': Cannot resolve reference to bean 'org.springframework.flex.core.MessageInterceptionAdvice#0' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.flex.core.MessageInterceptionAdvice#0': Cannot resolve reference to bean 'flexMessageInterceptor' while setting bean property 'messageInterceptors' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flexMessageInterceptor': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.flex.messaging.MessageTemplate org.hmil.sales.flex.FlexMessageInterceptor.defaultMessageTemplate; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultMessageTemplate' defined in ServletContext resource [/WEB-INF/spring/app-config.xml]: Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '_messageBroker': Cannot resolve reference to bean '_messageBrokerEndpointProcessor' while setting bean property 'configProcessors' with key [3]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '_messageBrokerEndpointProcessor': Cannot resolve reference to bean 'org.springframework.flex.core.EndpointServiceMessagePointcutAdvisor#1' while setting constructor argument with key [1]; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'org.springframework.flex.core.EndpointServiceMessagePointcutAdvisor#1': Requested bean is currently in creation: Is there an unresolvable circular reference?
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedList(BeanDefinitionValueResolver.java:353)
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:153)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1360)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1118)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:322)
    	... 35 more
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.web.DefaultSecurityFilterChain#0': Cannot create inner bean '(inner bean)' of type [org.springframework.security.web.util.AnyRequestMatcher] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.flex.core.EndpointServiceMessagePointcutAdvisor#1': Cannot resolve reference to bean 'org.springframework.flex.core.MessageInterceptionAdvice#0' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.flex.core.MessageInterceptionAdvice#0': Cannot resolve reference to bean 'flexMessageInterceptor' while setting bean property 'messageInterceptors' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flexMessageInterceptor': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.flex.messaging.MessageTemplate org.hmil.sales.flex.FlexMessageInterceptor.defaultMessageTemplate; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultMessageTemplate' defined in ServletContext resource [/WEB-INF/spring/app-config.xml]: Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '_messageBroker': Cannot resolve reference to bean '_messageBrokerEndpointProcessor' while setting bean property 'configProcessors' with key [3]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '_messageBrokerEndpointProcessor': Cannot resolve reference to bean 'org.springframework.flex.core.EndpointServiceMessagePointcutAdvisor#1' while setting constructor argument with key [1]; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'org.springframework.flex.core.EndpointServiceMessagePointcutAdvisor#1': Requested bean is currently in creation: Is there an unresolvable circular reference?
    And the error continues

  4. #4
    Join Date
    Feb 2009
    Posts
    135

    Default

    Hi,

    I am trying to publish messages from my flex interceptor. (when using annotations I encounter the above problem) so I configured like below in flex servlet

    Code:
    <!-- Flex-specific Configuration -->
    	<flex:message-broker>	
    		<flex:message-interceptor ref="flexMessageInterceptor"/>
    	  	<flex:message-service default-channels="my-streaming-amf,my-longpolling-amf,my-polling-amf" />
    		<flex:secured>
    			<flex:secured-channel channel="my-amf" access="IS_AUTHENTICATED_FULLY" />
    			<flex:secured-channel channel="my-secure-amf" access="IS_AUTHENTICATED_FULLY" />
    			<flex:secured-channel channel="my-http" access="IS_AUTHENTICATED_FULLY" />
    			<flex:secured-channel channel="my-secure-http" access="IS_AUTHENTICATED_FULLY" />
    			<flex:secured-endpoint-path pattern="**/messagebroker/**" access="IS_AUTHENTICATED_FULLY" />	
    		</flex:secured> 
     	</flex:message-broker>
    	
     	<bean id="flexMessageInterceptor" class="org.hmil.sales.flex.FlexMessageInterceptor">
     	<constructor-arg ref="logFeeder"></constructor-arg>
     	</bean>
     
    
    	<!-- Messaging destinations -->	
    	<flex:message-destination id="simple-feed" />	
    	 
    	<!-- MessageTemplate makes it easy to publish messages -->
    	<bean id="defaultMessageTemplate" class="org.springframework.flex.messaging.MessageTemplate" />
     
    	<bean id="logFeeder" class="org.hmil.sales.flex.LogFeeder">
    		<constructor-arg ref="defaultMessageTemplate" />
    		<flex:remoting-destination />
    	</bean>
    And I get the below error

    Code:
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name '_messageBrokerDefaultHandlerMapping': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '_messageBroker': Cannot resolve reference to bean '_messageBrokerEndpointProcessor' while setting bean property 'configProcessors' with key [3]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '_messageBrokerEndpointProcessor': Cannot resolve reference to bean 'org.springframework.flex.core.EndpointServiceMessagePointcutAdvisor#1' while setting constructor argument with key [1]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.flex.core.EndpointServiceMessagePointcutAdvisor#1': Cannot resolve reference to bean 'org.springframework.flex.core.MessageInterceptionAdvice#0' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.flex.core.MessageInterceptionAdvice#0': Cannot resolve reference to bean 'flexMessageInterceptor' while setting bean property 'messageInterceptors' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flexMessageInterceptor' defined in ServletContext resource [/WEB-INF/flex-servlet.xml]: Cannot resolve reference to bean 'logFeeder' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'logFeeder' defined in ServletContext resource [/WEB-INF/flex-servlet.xml]: Cannot resolve reference to bean 'defaultMessageTemplate' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultMessageTemplate' defined in ServletContext resource [/WEB-INF/flex-servlet.xml]: Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name '_messageBroker': FactoryBean which is currently in creation returned null from getObject
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:609)
    	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:469)
    	at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:442)
    	at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:458)
    	at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:339)
    	at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:306)
    	at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127)
    	at javax.servlet.GenericServlet.init(GenericServlet.java:160)
    	at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1228)
    	at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1147)
    	at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1043)
    	at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4957)
    	at org.apache.catalina.core.StandardContext$3.call(StandardContext.java:5284)
    	at org.apache.catalina.core.StandardContext$3.call(StandardContext.java:5279)
    	at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    	at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    	at java.lang.Thread.run(Thread.java:722)
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '_messageBroker': Cannot resolve reference to bean '_messageBrokerEndpointProcessor' while setting bean property 'configProcessors' with key [3]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '_messageBrokerEndpointProcessor': Cannot resolve reference to bean 'org.springframework.flex.core.EndpointServiceMessagePointcutAdvisor#1' while setting constructor argument with key [1]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.flex.core.EndpointServiceMessagePointcutAdvisor#1': Cannot resolve reference to bean 'org.springframework.flex.core.MessageInterceptionAdvice#0' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.flex.core.MessageInterceptionAdvice#0': Cannot resolve reference to bean 'flexMessageInterceptor' while setting bean property 'messageInterceptors' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flexMessageInterceptor' defined in ServletContext resource [/WEB-INF/flex-servlet.xml]: Cannot resolve reference to bean 'logFeeder' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'logFeeder' defined in ServletContext resource [/WEB-INF/flex-servlet.xml]: Cannot resolve reference to bean 'defaultMessageTemplate' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultMessageTemplate' defined in ServletContext resource [/WEB-INF/flex-servlet.xml]: Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name '_messageBroker': FactoryBean which is currently in creation returned null from getObject
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolve

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •