Announcement Announcement Module
Collapse
No announcement yet.
Spring Integration + Spring Java Config Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Integration + Spring Java Config

    1. Almost all my beans are configured using Spring Java Config.

    2. I have just added Spring Integration to my system, and plan to use it to send pager messages to my DAO. My App context looks like this:
    Code:
    ?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xmlns:context="http://www.springframework.org/schema/context"
    	xmlns:integration="http://www.springframework.org/schema/integration"
    	xsi:schemaLocation="
    	http://www.springframework.org/schema/beans 		http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
        http://www.springframework.org/schema/integration 	http://www.springframework.org/schema/integration/spring-integration-1.0.xsd
    	http://www.springframework.org/schema/context 		http://www.springframework.org/schema/context/spring-context-2.5.xsd">
    
    	<bean class="myApp.AppConfig"/>
    	
    	<bean class="org.springframework.config.java.process.ConfigurationPostProcessor"/>
    	
    	<context:load-time-weaver/>
    	
    	<bean id="securityAspect" class="myApp.aop.SecurityAspect" factory-method="aspectOf">
    		<property name="securityInterceptor"><ref bean="securityInterceptor"/></property>
    	</bean>
    
    	<integration:annotation-config/>
    	
    	<integration:channel id="pagerChannel"/>
    	
    </beans>
    When I use annotiation configuration to specify my service activator, everything works great.
    Code:
    @MessageEndpoint
    public class DataAccessJdbcImpl implements DataAccess {
    ...
    	@ServiceActivator(inputChannel="pagerChannel")
    	public String sendPage(PagerMessage message) {
                    ...
    		return "Ok";
    	}
    
    }
    However, if I try XML-only configuration, with the annotations removed, it doesn't seem to work.
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    ...
    	<integration:channel id="pagerChannel"/>
    	
    	<integration:service-activator input-channel="pagerChannel" ref="dataAccess" method="sendPage"/>
    	
    </beans>
    NOTE: See next message for actual stack trace.

    I am wondering if this is actually Spring Java Config's fault, or perhaps the "ref" argument only works as a local reference.

  • #2
    This is the stack trace I get with the pure XML configuration:
    Code:
    2008/12/10 14:39:41 [ INFO] MyAppProperties.getLogger - DB logging enabled? false
    2008/12/10 14:39:41 [ INFO] ClassPathXmlApplicationContext.prepareRefresh - Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@8ab08f: display name [org.springframework.context.support.ClassPathXmlApplicationContext@8ab08f]; startup date [Wed Dec 10 14:39:41 EST 2008]; root of context hierarchy
    2008/12/10 14:39:41 [ INFO] XmlBeanDefinitionReader.loadBeanDefinitions - Loading XML bean definitions from class path resource [applicationContext.xml]
    2008/12/10 14:39:42 [ INFO] ThreadPoolTaskExecutor.initialize - Initializing ThreadPoolExecutor
    2008/12/10 14:39:42 [ INFO] XmlBeanDefinitionReader.loadBeanDefinitions - Loading XML bean definitions from class path resource [aopContext.xml]
    2008/12/10 14:39:42 [ INFO] DefaultListableBeanFactory.registerBeanDefinition - Overriding bean definition for bean 'loadTimeWeaver': replacing [Generic bean: class [org.springframework.context.weaving.DefaultContextLoadTimeWeaver]; scope=singleton; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] with [Generic bean: class [org.springframework.context.weaving.DefaultContextLoadTimeWeaver]; scope=singleton; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null]
    2008/12/10 14:39:42 [ INFO] ClassPathXmlApplicationContext.obtainFreshBeanFactory - Bean factory for application context [org.springframework.context.support.ClassPathXmlApplicationContext@8ab08f]: org.springframework.beans.factory.support.DefaultListableBeanFactory@ae97c4
    2008/12/10 14:39:51 [ INFO] DefaultContextLoadTimeWeaver.setBeanClassLoader - Found Spring's JVM agent for instrumentation
    2008/12/10 14:39:52 [ INFO] DefaultListableBeanFactory.destroySingletons - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@ae97c4: defining beans [myApp.AppConfig#0,org.springframework.config.java.process.ConfigurationPostProcessor#0,org.springframework.context.weaving.AspectJWeavingEnabler#0,loadTimeWeaver,securityAspect,errorChannel,org.springframework.integration.channel.MessagePublishingErrorHandler#0,taskScheduler,pagerChannel,org.springframework.integration.handler.ServiceActivatingHandler#0,org.springframework.integration.config.ConsumerEndpointFactoryBean#0,org.springframework.context.weaving.AspectJWeavingEnabler#1,cacheManager,methodCache,cachingAspect]; root of factory hierarchy
    2008/12/10 14:39:52 [ INFO] DefaultContextLoadTimeWeaver.destroy - Removing all registered transformers for class loader: sun.misc.Launcher$AppClassLoader
    FAILED CONFIGURATION: @BeforeClass classSetup
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.integration.config.ConsumerEndpointFactoryBean#0': Cannot resolve reference to bean 'org.springframework.integration.handler.ServiceActivatingHandler#0' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.integration.handler.ServiceActivatingHandler#0': Cannot resolve reference to bean 'dataAccess' while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'dataAccess' is defined
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:275)
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:104)
    	at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:479)
    	at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:162)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:925)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:835)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getSingletonFactoryBeanForTypeCheck(AbstractAutowireCapableBeanFactory.java:682)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryBean(AbstractAutowireCapableBeanFactory.java:614)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.isTypeMatch(AbstractBeanFactory.java:450)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:223)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:303)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:297)
    	at org.springframework.context.support.AbstractApplicationContext.getBeansOfType(AbstractApplicationContext.java:942)
    	at org.springframework.config.java.process.ConfigurationProcessor.copyBeanPostProcessors(ConfigurationProcessor.java:187)
    	at org.springframework.config.java.process.ConfigurationProcessor.<init>(ConfigurationProcessor.java:158)
    	at org.springframework.config.java.process.ConfigurationPostProcessor.postProcessBeanFactory(ConfigurationPostProcessor.java:123)
    	at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:554)
    	at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:537)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:363)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)
    	at myApp.utils.TestPagingSystem.classSetup(TestPagingSystem.java:27)
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.integration.handler.ServiceActivatingHandler#0': Cannot resolve reference to bean 'dataAccess' while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'dataAccess' is defined
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:275)
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:104)
    	at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:479)
    	at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:162)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:925)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:835)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:440)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:269)
    	... 43 more
    Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'dataAccess' is defined
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:387)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:968)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:246)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:269)
    	... 58 more
    ... Removed 22 stack frames

    Comment


    • #3
      Hi Greg,

      Is this happening against SJC 1.0.0.M4? If so, I've got a hunch as to the problem. Try it against the latest nightly snapshot and let me know if the error persists.

      Comment


      • #4
        Poof! It works! I replaced spring-javaconfig-1.0.0.M3 with org.springframework.config.java-1.0.0.CI-588.jar, and it works! I saw a whole slew of beans suddenly get advertised. Is there any projection for when the next M5 will be released?

        Thanks Chris for that fast response.

        Comment


        • #5
          Nice! Indeed... thank you Chris.

          Comment


          • #6
            There is not currently a release date for M5. It will probably release with Spring 3.0 M2 (because it will end up depending on that milestone).

            Glad to hear this worked.

            Comment

            Working...
            X