@SpringBean only injects dependencies into classes that inherit from Wicket Component . @Autowired only injects dependencies into classes created by Spring itself. This means that you cannot automatically add a dependency to an object created with new .
(Edit: you can also add an @SpringBean injection to your class by typing: InjectorHolder.getInjector().inject(this); )
My usual workaround for this is to use my application class to help. (I'm a little puzzled by your use of new Application(...) . I assume this is not really org.apache.wicket.Application .) For example:
public class MyApplication extends AuthenticatedWebApplication implements ApplicationContextAware { private ApplicationContext ctx; public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { this.ctx = applicationContext; } public static MyApplication get() { return (MyApplication) WebApplication.get(); } public static Object getSpringBean(String bean) { return get().ctx.getBean(bean); } public static <T> T getSpringBean(Class<T> bean) { return get().ctx.getBean(bean); } .... }
In my Spring context:
<bean id="wicketApplication" class="uk.co.humboldt.Project.MyApplication"/>
Then my helper object looks for a service on request:
public class HelperObject { private Service getService() { return MyApplication.getSpringBean(Service.class); }
source share