5

我正在使用 Spring 3,并希望将一些依赖项注入到作为 taglib 一部分的类中。我可以想象一些使用constructor-arg的混乱,但我希望其他人有更好的主意。

4

2 回答 2

6

如果您决定从自定义标签访问服务或 DAO,那么您需要从标签访问 ApplicationContext,然后获取 Bean。

ApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(pageContext.getServletContext()); 
MyService myService = applicationContext.getBean(MyService.class);
myService.doSomething();
于 2010-12-09T10:42:08.787 回答
1

还有http://www.shredzone.org/projects/jshred/wiki/Spring_supported_Tag_Libraries - 这通过为每个 taglib 类创建一个代理类来处理与 Spring 的交互,并在需要时使用 Spring 生成 taglib 的实例.

于 2013-03-22T11:07:20.940 回答