Currently my jsp 2.0 tags that need spring beans use this code:
ac = WebApplicationContextUtils.getWebApplicationContext( servletContext);
ac.getBeansOfType(
Another way to achieve this is use a static property to hold the dependency. Just like below:
public class InjectedTag extends SimpleTagSupport {
//In order to hold the injected service, we have to declare it as static
private static AService _service;
/***/
@Override
public void doTag() throws IOException {
getJspContext().getOut().
write("Service injected: " + _service + "
");
}
public void setService(AService service) {
_service = service;
}
}
In you applicationcontext, you have to register both so that the JSP tag can get one chance to be initiated by Spring. We we Go with the magic...
Cool huh, now aService is visible in our JSP tag :)