![](/img/trans.png)
[英]is there an elegant way to inject a spring managed bean into a java custom/simple tag
[英]Inject Bean in Custom tag Java - @Configurable
我在將服務注入我創建的自定義標記時遇到問題:
@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);
@Configurable需要使用AspectJ啟用編譯時間或加載時間編織。 它不適用於普通的Spring AOP,請您確認您的項目使用AspectJ。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.