0

I am having trouble injecting a service into a custom tag I created:

@Configurable
public MyTag extends BodyTagSupport{

 @Autowired
 private MyService service;

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

Is there a way to inject beans using @Configurable in Custom Tags? I do not want to use following approach to inject beans:

 ServletContext sc = ((PageContext) getJspContext()).getServletContext();
 ApplicationContext context = 
   WebApplicationContextUtils.getWebApplicationContext(sc);
aces.
  • 3,902
  • 10
  • 38
  • 48

1 Answers1

2

@Configurable requires Compile time or load time weaving using AspectJ to be enabled. It will not work with normal Spring AOP, can you please confirm your project uses AspectJ.

Biju Kunjummen
  • 49,138
  • 14
  • 112
  • 125
  • No, It does not, unfortunately. However, if the project used AspectJ. The approach I used will work right? Or am I still missing something? Also, is there any annotation that I could use for Spring-driven bean injection here? – aces. Jul 03 '12 at 19:57
  • Yes, it will work if you have AspectJ enabled for your project. Outside of Aspectj the only approach is one recommended in this link: http://stackoverflow.com/q/3445908/204788 – Biju Kunjummen Jul 03 '12 at 20:05