Announcement Announcement Module
No announcement yet.
Inject spring bean to JSP tag Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Inject spring bean to JSP tag

    Hi All,

    I'm under the pressure injecting spring beans to JSP tags, after surfing the internet, i figured out the AOP way(Use @Configurable etc.) might be the ideal solution. However, it requires the either AspectJ Load-time weaving (LTW) or Compile time weaving(Using Maven/Ant), which both turns to me panic. I like neither. As they all seem heavily depending on the Spring. See

    Finally, an usable, might not elegant, solution comes up. As below:
    public class SimplePaginationTag extends BodyTagSupport {

    private static SearcherManagerFactory searcherManagerFactory;

    public void setSearcherManagerFactory(
    SearcherManagerFactory searcherManagerFactory) {
    this.searcherManagerFactory = searcherManagerFactory;
    The trick is declare the dependency as static variable(for me the dependency is of most time singlestone instance, so i believe it makes no difference), then in the application context file, config as below:
    <bean class="com.mwg.documentcontrol.tags.SimplePaginati onTag">
    <property name="searcherManagerFactory">
    <ref bean="searcherManagerFactory"/>
    this makes Spring container to initiate the SimplePaginationTag at application startup and inject the searcherManagerFactory to my SimplePaginationTag. As searcherManagerFactory is static variable, this injection lives in the whole application life time.

    The purpose i post my solution here is to identify is there some drawback for such workaround? Is there some smartest way of handling this problem ?