Thank you, now it works.
On Tue, Nov 10, 2009 at 8:29 PM, Pieter Degraeuwe <
[email protected]> wrote:
> You are getting this exception from a unittest. When you use WicketTester
> in
> combination with Spring injection, you have to tweak it a bit:
> You have to add the spring applicationContext to the mock ServletContext:
>
> Soe here a expect that you already did construct the spring
> applicationContext. Creating the WicketTester:
>
> tester = new WicketTester(createWebApplication()) {
> @Override
> public ServletContext newServletContext(String path) {
> MockServletContext servletContext = (MockServletContext)
> super.newServletContext(path);
>
>
> servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,
> applicationContext);
> return servletContext;
> }
> };
> tester.getWicketSession().setLocale(getLocale());
> new SpringComponentInjector(tester.getApplication(),
> applicationContext);
> testerHolder = tester;
>
>
> That should do it:
>
> 2009/11/10 Владимир Михайленко <[email protected]>
>
> > Hello.
> >
> > I just created wicket quickstart project via maven and want add Spring DI
> > to
> > Wicket. So I added to WicketApplication:
> >
> > @Override
> > protected void init()
> > {
> > super.init();
> > addComponentInstantiationListener(new
> > SpringComponentInjector(this));
> > }
> >
> > In web.xml I added:
> >
> > <context-param>
> > <param-name>contextConfigLocation</param-name>
> > <param-value>/WEB-INF/applicationContext.xml</param-value>
> > </context-param>
> >
> > <filter>
> > <filter-name>wicket.jobmd</filter-name>
> >
> > <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
> > <init-param>
> > <param-name>applicationFactoryClassName</param-name>
> >
> >
> >
> <param-value>org.apache.wicket.spring.SpringWebApplicationFactory</param-value>
> > </init-param>
> > <init-param>
> > <param-name>applicationBean</param-name>
> > <param-value>wicketApplication</param-value>
> > </init-param>
> > </filter>
> >
> > <listener>
> >
> >
> >
> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
> > </listener>
> >
> > In pom.xml:
> >
> > <dependency>
> > <groupId>org.apache.wicket</groupId>
> > <artifactId>wicket-spring</artifactId>
> > <version>${wicket.version}</version>
> > </dependency>
> > <dependency>
> > <groupId>org.springframework</groupId>
> > <artifactId>spring</artifactId>
> > <version>2.5.6</version>
> > </dependency>
> >
> > In applicationContext.xml:
> >
> > <bean id="wicketApplication"
> > class="com.mihailenco.WicketApplication"></bean>
> >
> > Then when I build project in latest stable NetBeans I get this error in
> > console:
> >
> > Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 1.579 sec
> > <<< FAILURE!
> > testRenderMyPage(com.mihailenco.TestHomePage) Time elapsed: 1.435 sec
> <<<
> > ERROR!
> > java.lang.IllegalStateException: No WebApplicationContext found: no
> > ContextLoaderListener registered?
> > at
> >
> >
> org.springframework.web.context.support.WebApplicationContextUtils.getRequiredWebApplicationContext(WebApplicationContextUtils.java:70)
> > at
> >
> >
> org.apache.wicket.spring.injection.annot.SpringComponentInjector.<init>(SpringComponentInjector.java:72)
> > at
> com.mihailenco.WicketApplication.init(WicketApplication.java:24)
> > at
> > org.apache.wicket.protocol.http.WicketFilter.init(WicketFilter.java:708)
> > at
> >
> >
> org.apache.wicket.protocol.http.MockWebApplication.<init>(MockWebApplication.java:168)
> > at
> >
> >
> org.apache.wicket.util.tester.BaseWicketTester.<init>(BaseWicketTester.java:217)
> > at
> > org.apache.wicket.util.tester.WicketTester.<init>(WicketTester.java:317)
> > at
> > org.apache.wicket.util.tester.WicketTester.<init>(WicketTester.java:300)
> > at com.mihailenco.TestHomePage.setUp(TestHomePage.java:16)
> > at junit.framework.TestCase.runBare(TestCase.java:128)
> > at junit.framework.TestResult$1.protect(TestResult.java:106)
> > at junit.framework.TestResult.runProtected(TestResult.java:124)
> > at junit.framework.TestResult.run(TestResult.java:109)
> > at junit.framework.TestCase.run(TestCase.java:120)
> > at junit.framework.TestSuite.runTest(TestSuite.java:230)
> > at junit.framework.TestSuite.run(TestSuite.java:225)
> > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> > at
> >
> >
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> > at
> >
> >
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> > at java.lang.reflect.Method.invoke(Method.java:597)
> > at
> >
> org.apache.maven.surefire.junit.JUnitTestSet.execute(JUnitTestSet.java:213)
> > at
> >
> >
> org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
> > at
> >
> >
> org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
> > at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
> > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> > at
> >
> >
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> > at
> >
> >
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> > at java.lang.reflect.Method.invoke(Method.java:597)
> > at
> >
> >
> org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:345)
> > at
> >
> >
> org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009)
> >
> > Did I missed something? Thank you.
> >
>
>
>
> --
> Pieter Degraeuwe
> Systemworks bvba
> Belgiëlaan 61
> 9070 Destelbergen
> GSM: +32 (0)485/68.60.85
> Email: [email protected]
> visit us at http://www.systemworks.be
>