Wicket WebApplication/WebPage circular dependency using spring
In my wicket spring based applications, I have this method to inject the spring manager to the WebApplication
class:
private void initManager() {
ApplicationContext applicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
this.manager = (MyManager) applicationContext.getBean("manager");
}
I usually setup the internal error page inside the init
method of my WebApplication
class. Sometimes I also mount some bookmarkable pages:
public class MyApplication extends WebApplication {
@Override
protected void init() {
IApplicationSettings applicationSettings = getApplicationSettings();
applicationSettings.setInternalErrorPage(ErrorPage.cla开发者_C百科ss);
mountBookmarkablePage("privacy", PrivacyPage.class);
}
//............
}
My WebPage
classes usually depend on my manager class, for instance:
public class ErrorPage extends WebPage {
public ErrorPage() {
MyApplication application = (MyApplication) getApplication();
add(new EmailLink(application.getManager().getMailSupport()));
}
}
So, my WebApplication
class refers to one or more pages, and my pages refer to the WebApplication
class. Is this a circular dependency? If yes, how can I avoid it?
I would say it is not a circular dependency but it is a configuration.
However, I think you can always inject your manager bean to the web page class as well with autowiring.
EDIT:
You may also need to enable spring annotations in applicationContext.xml as well and add some new dependencies if not already in classpath
see applicationContext.xml sample at this address and your will be pretty much similar except the scan package name. Update those values accordingly.
public class ErrorPage extends WebPage {
@Autowired
private MyManager myManager;
//setter getter methods as well
}
精彩评论