[ 
https://issues.apache.org/jira/browse/WICKET-2487?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12758910#action_12758910
 ] 

Ralf Ebert commented on WICKET-2487:
------------------------------------

Even better, make the application a spring bean (as described in Wicket in 
Action), let the application implement ApplicationContextAware and create+add 
the SpringComponentInjector there:

public class SomeWicketApplication extends WebApplication implements 
ApplicationContextAware {

        public void setApplicationContext(ApplicationContext 
applicationContext) throws BeansException {
                addComponentInstantiationListener(new 
SpringComponentInjector(this, applicationContext));
        }

}

> SpringComponentInjector and AbstractJUnit4SpringContextTests
> ------------------------------------------------------------
>
>                 Key: WICKET-2487
>                 URL: https://issues.apache.org/jira/browse/WICKET-2487
>             Project: Wicket
>          Issue Type: Improvement
>          Components: wicket-spring
>    Affects Versions: 1.4.1
>            Reporter: Ralf Ebert
>            Assignee: Igor Vaynberg
>
> SpringComponentInjector goes to WebApplicationContextUtils to resolve the 
> application context. In tests derived from AbstractJUnit4SpringContextTests 
> this doesn't work.
> Workaround:
> 1) Make the SpringComponentInjector configurable for your app:
> public class SomeWicketApplication extends WebApplication {
>       @Override
>       protected void init() {
>               addComponentInstantiationListener(createSpringInjector());
>       }
>       protected SpringComponentInjector createSpringInjector() {
>               return new SpringComponentInjector(this);
>       }
> }
> 2) configure it correctly for the test:
> @ContextConfiguration(locations = { "classpath:spring.xml" })
> public class TestHomePage extends AbstractJUnit4SpringContextTests {
>       private WicketTester tester;
>       @Before
>       public void setUp() {
>               SomeWicketApplication app = new SomeWicketApplication() {
>                       @Override
>                       protected SpringComponentInjector 
> createSpringInjector() {
>                               return new SpringComponentInjector(this, 
> applicationContext);
>                       }
>               };
>               tester = new WicketTester(app);
>       }
> }
> Shouldn't there be a better/easier way to accomplish this?

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to