Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Problem deploying Spring Integration as a WAR\EAR file

  1. #1
    Join Date
    Jun 2011
    Location
    Sydney, Australia
    Posts
    32

    Default Problem deploying Spring Integration as a WAR\EAR file

    Hi,

    I am getting org.springframework.beans.factory.BeanDefinitionSt oreException with my current setup of spring integration within a ear/war.

    The failure occurs when trying to load the following spring integration config file:

    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:integration="http://www.springframework.org/schema/integration"
    	xmlns:file="http://www.springframework.org/schema/integration/file"
    	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-2.0.xsd
    			http://www.springframework.org/schema/integration/file
    			http://www.springframework.org/schema/integration/file/spring-integration-file-2.0.xsd">
    	
    	<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    		<property name="location" value="classpath:batch.properties"/>
    	</bean>
    	
    	<file:inbound-channel-adapter id="filesIn" directory="file:${ftp.dir}/input" prevent-duplicates="true">
    		<integration:poller id="poller" cron="*/5 * * * * *"/>
    	</file:inbound-channel-adapter>
    
    	<integration:service-activator input-channel="filesIn"
    	                               output-channel="filesOut"
                                       ref="handler"/>
    
    	<file:outbound-channel-adapter id="filesOut"
    								   directory="file:${ftp.dir}/output"
    								   delete-source-files="true"/>
    
    	<bean id="handler" class="my.FileCopyHandler"/>
    	
    
    </beans>

    Below are my configuration details:

    web.xml

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    	<display-name>MyWAR</display-name>
    	<context-param>
    		<param-name>contextConfigLocation</param-name>
    		<param-value>classpath:spring/my-batch-spring.xml</param-value>
    	</context-param>
    	<listener>
      		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    	</listener>
    	
    	<welcome-file-list>
    		<welcome-file>index.html</welcome-file>
    		<welcome-file>index.htm</welcome-file>
    		<welcome-file>index.jsp</welcome-file>
    		<welcome-file>default.html</welcome-file>
    		<welcome-file>default.htm</welcome-file>
    		<welcome-file>default.jsp</welcome-file>
    	</welcome-file-list>
    </web-app>
    my-batch-spring.xml

    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"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
    
    	<bean id="fileCopyProcessor" class="my.FileCopyProcessor"/>
    
    </beans>
    FileCopyProcessor.java

    Code:
    package my.process;
    
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.ApplicationEvent;
    import org.springframework.context.ApplicationListener;
    import org.springframework.context.event.ContextRefreshedEvent;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    
    public class FileCopyProcessor implements ApplicationListener {
    	
    	public FileCopyProcessor() {
    		System.out.println("calling constructor.................");
    	}
    
    	@Override
    	public void onApplicationEvent(ApplicationEvent event) {
    		
    		if(event instanceof ContextRefreshedEvent) {
    			System.out.println("I am being called");
    			ApplicationContext context = new ClassPathXmlApplicationContext("/integration/copy-files.xml", FileCopyProcessor.class);
    		}
    		
    	}
    }

    Stack trace :

    Code:
    [7/06/11 17:29:40:876 EST] 000000e7 XmlWebApplica I org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory Bean factory for application context [org.springframework.web.context.support.XmlWebApplicationContext@1a5a1a5a]: org.springframework.beans.factory.support.DefaultListableBeanFactory@79667966
    [7/06/11 17:29:50:360 EST] 000000e7 SystemOut     O calling constructor.................
    [7/06/11 17:29:53:798 EST] 000000e7 DefaultListab I org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@79667966: defining beans [fileCopyProcessor]; root of factory hierarchy
    [7/06/11 17:29:53:814 EST] 000000e7 SystemOut     O I am being called
    [7/06/11 17:29:54:501 EST] 000000e7 ClassPathXmlA I org.springframework.context.support.AbstractApplicationContext prepareRefresh Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@3b4c3b4c: display name [org.springframework.context.support.ClassPathXmlApplicationContext@3b4c3b4c]; startup date [Tue Jun 07 17:29:54 EST 2011]; root of context hierarchy
    [7/06/11 17:29:54:501 EST] 000000e7 XmlBeanDefini I org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions Loading XML bean definitions from class path resource [/integration/copy-files.xml]
    [7/06/11 17:30:05:860 EST] 000000e7 DefaultListab I org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@79667966: defining beans [fileCopyProcessor]; root of factory hierarchy
    [7/06/11 17:30:05:860 EST] 000000e7 ContextLoader E org.springframework.web.context.ContextLoader initWebApplicationContext Context initialization failed
                                     org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [/integration/copy-files.xml]; nested exception is java.lang.NullPointerException
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:420)
    
    .............more error........
    
    Caused by: java.lang.NullPointerException
    	at org.springframework.beans.factory.support.BeanDefinitionReaderUtils.generateBeanName(BeanDefinitionReaderUtils.java:115)
    	at org.springframework.beans.factory.support.BeanDefinitionReaderUtils.generateBeanName(BeanDefinitionReaderUtils.java:159)
    	at org.springframework.beans.factory.support.DefaultBeanNameGenerator.generateBeanName(DefaultBeanNameGenerator.java:31)
    	at org.springframework.beans.factory.xml.XmlReaderContext.generateBeanName(XmlReaderContext.java:77)
    	at org.springframework.beans.factory.xml.AbstractBeanDefinitionParser.resolveId(AbstractBeanDefinitionParser.java:102)
    	at org.springframework.beans.factory.xml.AbstractBeanDefinitionParser.parse(AbstractBeanDefinitionParser.java:59)
    	at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:69)
    	at org.springframework.integration.config.xml.AbstractIntegrationNamespaceHandler.parse(AbstractIntegrationNamespaceHandler.java:53)
    	at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1297)
    	at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1287)
    	at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:135)
    	at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:92)
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:507)
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:398)
    Can anyone suggest something?
    Last edited by leogags; Jun 7th, 2011 at 02:50 AM. Reason: Error stack attached

  2. #2
    Join Date
    May 2011
    Location
    Cracow, Poland
    Posts
    53

    Default

    Hi!

    Make sure that 'batch.properties' is on the classpath....

  3. #3
    Join Date
    Jun 2011
    Location
    Sydney, Australia
    Posts
    32

    Default

    Hi,

    Thanks for the reply but the properties file is in the classpath. Moreoever, even a simple helloWorld example throws the same exception.

    helloWorldDemo.xml

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans:beans xmlns="http://www.springframework.org/schema/integration"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xmlns:beans="http://www.springframework.org/schema/beans"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans
    			http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    			http://www.springframework.org/schema/integration
    			http://www.springframework.org/schema/integration/spring-integration-2.0.xsd">
    
    	<channel id="inputChannel"/>
    
    	<channel id="outputChannel">
    		<queue capacity="10"/>
    	</channel>
    
    	<service-activator input-channel="inputChannel" output-channel="outputChannel" ref="helloService" method="sayHello"/>
    
    	<beans:bean id="helloService" class="my.service.HelloService"/>
    
    </beans:beans>
    Appears to be a configuration issue. Not sure what/where the problem is!!

  4. #4
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,139

    Default

    Looks like you are trying to use Spring Integration 2.0 with Spring 2.5; confirmed by the line numbers in your stack trace.

    SI needs Spring 3.0.

    Specifically, SI 2.0.4.RELEASE needs Spring 3.0.5.RELEASE.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  5. #5
    Join Date
    Jun 2011
    Location
    Sydney, Australia
    Posts
    32

    Default

    Hi Gary,

    You are spot on. I just figured out the same. I ran the same example with spring 3.0.5 release and it works as expected. Thanks.

    Could you please elaborate on how you its obvious to you by the stack trace "confirmed by the line numbers in your stack trace".?

  6. #6
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,139

    Default

    Quote Originally Posted by leogags View Post
    Could you please elaborate on how you its obvious to you by the stack trace "confirmed by the line numbers in your stack trace".?
    Simply that the line numbers in your trace didn't make sense, looking at the current (3.0.x) source code...

    Code:
    (XmlBeanDefinitionReader.java:420)
    (BeanDefinitionReaderUtils.java:115)
    (BeanDefinitionReaderUtils.java:159)
    ...didn't make any sense; they point at either comments, or white space in current code. I had to go back to 2008 source code for them to make sense.

    BTW, as a general point, for all "viewers", when posting questions like this - it's always a good idea to specify exactly what software versions you are using - it will save us having to this kind of detective work to figure it out.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  7. #7
    Join Date
    Jun 2011
    Location
    Sydney, Australia
    Posts
    32

    Default

    Thanks Gary. Noted.

    I have got the file channel working now. However, when I put a file in the input folder, its been picked up twice.

    [8/06/11 12:23:30:010 EST] 0000002d FileReadingMe I org.springframework.integration.file.FileReadingMe ssageSource receive Created message: [[Payload=c:\test\ftp\input\New Text Document 4.txt][Headers={timestamp=1307499810010, id=25e0b266-682d-453d-a278-da3fdbb03a6e}]]
    [8/06/11 12:23:30:010 EST] 0000002e FileReadingMe I org.springframework.integration.file.FileReadingMe ssageSource receive Created message: [[Payload=c:\test\ftp\input\New Text Document 4.txt][Headers={timestamp=1307499810010, id=171e5aac-1df7-4210-aa3e-8e085f8c13d3}]]
    [8/06/11 12:23:30:010 EST] 0000002d SystemOut O Copying file: c:\test\ftp\input\New Text Document 4.txt
    [8/06/11 12:23:30:010 EST] 0000002e SystemOut O Copying file: c:\test\ftp\input\New Text Document 4.txt


    My poller is configured as a cron:

    <file:inbound-channel-adapter id="filesIn" directory="file:${ftp.dir}/input" prevent-duplicates="true">
    <integrationoller id="poller" cron="*/5 * * * * *"/>
    </file:inbound-channel-adapter>

    Is there any explanation for this?

    Update:

    If I run the same program on a dual core windows machine, it runs only once. However, when I run in quad core windows machine, it runs twice. How do I control this?
    Last edited by leogags; Jun 7th, 2011 at 09:50 PM.

  8. #8
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,139

    Default

    Without more details, and given the timestamps, it looks like you have two instances of your application context running.

    Why are you using an ApplicationContextListener to load your /integration/copy-files.xml instead of simply <import/> ing it?

    You have no protection to handle multiple refreshes.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  9. #9
    Join Date
    Jun 2011
    Location
    Sydney, Australia
    Posts
    32

    Default

    Hi Gary,

    I changed the poller from cron to <integrationoller id="poller" receive-timeout="30000" fixed-rate="10"/> and now files are being picked up once only. Not sure if this is related to cron!

    Simply importing the config file doesn't work for me unless I am missing something. That is why I went down the path of ApplicationContextListener. If I remove the listener from the web.xml, the server is started but the file copy process doesn't start.

    Here are the revised config without the listener:

    web.xml

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    	<display-name>PPSRABatchWAR</display-name>
    	<context-param>
    		<param-name>contextConfigLocation</param-name>
    		<param-value>classpath:spring/my-batch-spring.xml</param-value>
    	</context-param>
    	
    	<welcome-file-list>
    		<welcome-file>index.html</welcome-file>
    		<welcome-file>index.htm</welcome-file>
    		<welcome-file>index.jsp</welcome-file>
    		<welcome-file>default.html</welcome-file>
    		<welcome-file>default.htm</welcome-file>
    		<welcome-file>default.jsp</welcome-file>
    	</welcome-file-list>
    </web-app>
    my-batch-spring.xml

    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"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
    
      	<!-- Import bean definitions -->
    	<import resource="classpath:integration/copy-files.xml" />
    	<!-- import resource="classpath:integration/helloWorldDemo.xml" / -->
    
    	<!--  bean id="fileCopyProcessor" class="my.process.FileCopyProcessor"/ -->
    
    </beans>

  10. #10
    Join Date
    Jun 2011
    Location
    Sydney, Australia
    Posts
    32

    Default

    Hi Gary,

    I would appreciate if you could tell me how the file poller (copy-files.xml) can be started after server startup without using the ApplicationContextListener in the web.xml.

    Thanks

Posting Permissions

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