在自定义标记Java中注入Bean - @Configurable

时间:2012-07-03 19:51:28

标签: java spring dependency-injection taglib

我无法将服务注入我创建的自定义标记中:

@Configurable
public MyTag extends BodyTagSupport{

 @Autowired
 private MyService service;

 @Override
 public int doStartTag(){
 ......
  service.callServiceMethod(); // service is null
 ....
 }
 .......
}

有没有办法在自定义标签中使用@Configurable注入bean?我不想使用以下方法来注入bean:

 ServletContext sc = ((PageContext) getJspContext()).getServletContext();
 ApplicationContext context = 
   WebApplicationContextUtils.getWebApplicationContext(sc);

1 个答案:

答案 0 :(得分:2)

@Configurable要求使用AspectJ启用编译时间或加载时间编织。它不适用于普通的Spring AOP,请您确认您的项目使用AspectJ。

相关问题