Ok... I did some further investigations. Apparently I don't need to configure <configutor:settings/> in my spring-configuration of the cocoon-block when all I want is to run the block with mvn jetty:run since an applicationContext.xml with <configutor:settings/> inside get's automatically generated. I don't know if this is wanted behavior or not?!
Anyway, When I use my production-spring-configuration like below, I don't run into problems as long as I do NOT include a spring-configuration including <configutor:settings/>. So leaving out the location "classpath:META-INF/app-context.xml" results in good execution of this test. I put this file in META-INF because putting it in META-INF/cocoon/spring results in Following exception: "Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Unable to read spring configurations from classpath*:META-INF/cocoon/spring; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Detected recursive loading of URL" app-context.xml ---------------------- <?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:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:configurator="http://cocoon.apache.org/schema/configurator" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:util="http://www.springframework.org/schema/util" xmlns:pipeline="http://cocoon.apache.org/schema/pipeline" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd http://cocoon.apache.org/schema/configurator http://cocoon.apache.org/schema/configurator/cocoon-configurator-1.0.1.x sd http://cocoon.apache.org/schema/pipeline http://cocoon.apache.org/schema/pipeline/cocoon-pipeline-1.0.xsd"> <configurator:settings /> </beans> --------------------------------------------------------- package com.nxp.spider.test; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.nxp.spider.Spider; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration( locations = { "classpath:META-INF/cocoon/spring/common-application-context.xml", "classpath:META-INF/cocoon/spring/common-controllers.xml", "classpath:META-INF/cocoon/spring/common-servlet-service.xml", "classpath:META-INF/app-context.xml" } ) public class SpiderTest { @Autowired @Qualifier("spider") private Spider spider; @Test public void testSettings() { System.out.println(spider); Assert.assertNotNull(spider); } } --------------------------------------------------------- So what's the deal here?? Am I missing some stupid detail or is the cocoon-spring-configurator messing up my unit-tests? Cheers, Robby Pelssers -----Original Message----- From: Steven Dolg [mailto:[email protected]] Sent: Friday, May 15, 2009 5:46 PM To: [email protected] Subject: Re: ClassCastException in cocoon-block-deployment when running junit test [cocoon-3] and using cocoon-spring-configurator Robby Pelssers schrieb: > > Hi all, > > I've been trying for quite some time to get a simple unit test working > for a cocoon 3-block where I'm also using the > 'cocoon-spring-configurator'. I added the files involved because I > have no clue if this is a configuration problem somehow giving me the > stacktrace below. > > Anybody who can help me out here? > > Many thx in advance. > > Robby > > *_src/main/resources/applicationContext.xml_* > > <?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:p="http://www.springframework.org/schema/p" > > xmlns:context="http://www.springframework.org/schema/context" > > xmlns:configurator="http://cocoon.apache.org/schema/configurator" > > xmlns:aop="http://www.springframework.org/schema/aop" > > xmlns:util="http://www.springframework.org/schema/util" > > xmlns:pipeline="http://cocoon.apache.org/schema/pipeline" > > xsi:schemaLocation=" > > http://www.springframework.org/schema/beans > http://www.springframework.org/schema/beans/spring-beans-2.5.xsd > > http://www.springframework.org/schema/aop > http://www.springframework.org/schema/aop/spring-aop-2.5.xsd > > http://www.springframework.org/schema/context > http://www.springframework.org/schema/context/spring-context-2.5.xsd > > http://www.springframework.org/schema/util > http://www.springframework.org/schema/util/spring-util-2.5.xsd > > http://cocoon.apache.org/schema/configurator > http://cocoon.apache.org/schema/configurator/cocoon-configurator-1.0.1.x sd > > http://cocoon.apache.org/schema/pipeline > http://cocoon.apache.org/schema/pipeline/cocoon-pipeline-1.0.xsd"> > > <configurator:settings /> > > <bean name="spider" class="com.nxp.spider.Spider" > > > <property name="settings" ref="settings"/> > > </bean> > > </beans> > > *_com.nxp.spider.Spider.java_* > > *package* com.nxp.spider; > > *import* org.apache.cocoon.configuration.Settings; > > *public* *class* Spider { > > *private* Settings settings; > > *public* *void* _setSettings_(Settings settings) { > > *this*.settings = settings; > > } > > *public* Settings getSettings() { > > *return* *this*.settings; > > } > > *public* String getRunningMode() { > > *return* getSettings().getRunningMode(); > > } > > *public* String toString() { > > *return* "Application running in mode '" + getRunningMode() + "'."; > > } > > } > > *_com.nxp.spider.test.SpiderTest_* > > *package* com.nxp.spider.test; > > *import* org.springframework.context.ApplicationContext; > > *import* > org.springframework.context.support.ClassPathXmlApplicationContext; > > *import* com.nxp.spider.Spider; > > *import* junit.framework.TestCase; > > *public* *class* SpiderTest *extends* TestCase { > > *private* ApplicationContext appContext; > > *protected* *void* setUp() *throws* Exception { > > *super*.setUp(); > > appContext = *new* > ClassPathXmlApplicationContext("application-context.xml"); > > } > > *protected* *void* tearDown() *throws* Exception { > > appContext = *null*; > > *super*.tearDown(); > > } > > *public* *void* testSpider() { > > Spider spider = (Spider) appContext.getBean("spider"); > > /assertNotNull/(spider); > > } > > } > > *_StackTrace when running SpiderTest [eclipse] or when running $ mvn > test -Dorg.apache.cocoon.mode=dev [cygwin]. I have declared junit 4.4 > as dependency._* > > org.springframework.beans.factory.BeanCreationException: Error > creating bean with name > 'org.apache.cocoon.blockdeployment.BlockContextURLStreamHandlerFactory' > defined in URL > [jar:file:/D:/maven/repo/org/apache/cocoon/cocoon-block-deployment/1.0.0 /cocoon-block-deployment-1.0.0.jar!/META-INF/cocoon/spring/cocoon-blockd eployment-protocol.xml]: > Initialization of bean failed; nested exception is > java.lang.ClassCastException: > org.springframework.context.support.ClassPathXmlApplicationContext > > at > org.springframework.beans.factory.support.AbstractAutowireCapableBeanFac tory.doCreateBean(AbstractAutowireCapableBeanFactory.java:480) > > at > org.springframework.beans.factory.support.AbstractAutowireCapableBeanFac tory$1.run(AbstractAutowireCapableBeanFactory.java:409) > > at java.security.AccessController.doPrivileged(Native Method) > > at > org.springframework.beans.factory.support.AbstractAutowireCapableBeanFac tory.createBean(AbstractAutowireCapableBeanFactory.java:380) > > at > org.springframework.beans.factory.support.AbstractBeanFactory$1.getObjec t(AbstractBeanFactory.java:264) > > at > org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.g etSingleton(DefaultSingletonBeanRegistry.java:222) > > at > org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean( AbstractBeanFactory.java:261) > > at > org.springframework.beans.factory.support.AbstractBeanFactory.getBean(Ab stractBeanFactory.java:185) > > at > org.springframework.beans.factory.support.AbstractBeanFactory.getBean(Ab stractBeanFactory.java:164) > > at > org.springframework.beans.factory.support.DefaultListableBeanFactory.pre InstantiateSingletons(DefaultListableBeanFactory.java:429) > > at > org.springframework.context.support.AbstractApplicationContext.finishBea nFactoryInitialization(AbstractApplicationContext.java:728) > > at > org.springframework.context.support.AbstractApplicationContext.refresh(A bstractApplicationContext.java:380) > > at > org.springframework.context.support.ClassPathXmlApplicationContext.<init >(ClassPathXmlApplicationContext.java:139) > > at > org.springframework.context.support.ClassPathXmlApplicationContext.<init >(ClassPathXmlApplicationContext.java:83) > > at com.nxp.spider.test.SpiderTest.setUp(SpiderTest.java:16) > > at junit.framework.TestCase.runBare(TestCase.java:132) > > at junit.framework.TestResult$1.protect(TestResult.java:110) > > at junit.framework.TestResult.runProtected(TestResult.java:128) > > at junit.framework.TestResult.run(TestResult.java:113) > > at junit.framework.TestCase.run(TestCase.java:124) > > at junit.framework.TestSuite.runTest(TestSuite.java:232) > > at junit.framework.TestSuite.run(TestSuite.java:227) > > at > org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.jav a:81) > > at > org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4Tes tReference.java:45) > > at > org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.ja va:38) > > at > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTe stRunner.java:460) > > at > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTe stRunner.java:673) > > at > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRun ner.java:386) > > at > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRu nner.java:196) > > Caused by: java.lang.ClassCastException: > org.springframework.context.support.ClassPathXmlApplicationContext > > at > org.apache.cocoon.blockdeployment.BlockContextURLStreamHandlerFactory.se tApplicationContext(BlockContextURLStreamHandlerFactory.java:55) > > at > org.springframework.context.support.ApplicationContextAwareProcessor.pos tProcessBeforeInitialization(ApplicationContextAwareProcessor.java:70) > > at > org.springframework.beans.factory.support.AbstractAutowireCapableBeanFac tory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapable BeanFactory.java:350) > > at > org.springframework.beans.factory.support.AbstractAutowireCapableBeanFac tory.initializeBean(AbstractAutowireCapableBeanFactory.java:1331) > > at > org.springframework.beans.factory.support.AbstractAutowireCapableBeanFac tory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473) > > ... 28 more > Caused by: java.lang.ClassCastException: org.springframework.context.support.ClassPathXmlApplicationContext at org.apache.cocoon.blockdeployment.BlockContextURLStreamHandlerFactory.se tApplicationContext(BlockContextURLStreamHandlerFactory.java:55) That line reads: WebApplicationContext webApplicationContext = (WebApplicationContext) applicationContext; Which basically means the block deployment subproject is for web apps. See also http://cocoon.apache.org/subprojects/block-deployment/1.1/1471_1_1.html Regards, Steven --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
