I'm using Spring 3 and want to inject some dependencies into a class that is part of a taglib. I can imagine some kludge using constructor-arg, but I'm hoping someone else has a better idea.
Should you decide to access a Service or DAO from a custom tag then you need to access the ApplicationContext from the tag and then get the Bean.
ApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(pageContext.getServletContext());
MyService myService = applicationContext.getBean(MyService.class);
myService.doSomething();
There is also http://www.shredzone.org/projects/jshred/wiki/Spring_supported_Tag_Libraries - this works by creating a proxy class for each taglib class handles the interaction with Spring, and uses Spring to generate an instance of the taglib when required.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With