2012-10-06 90 views
0

即時嘗試注入一個util類使用spring @Resource Annotation託管bean,但是當我運行應用程序時,我得到這個錯誤。無法注入託管bean中的@Resource註解

Caused by: com.sun.faces.spi.InjectionProviderException: javax.naming.NameNotFoundException: Name com.web.bean.Bond is not bound in this Context 
    at com.sun.faces.vendor.Tomcat6InjectionProvider.inject(Tomcat6InjectionProvider.java:84) 
    at com.sun.faces.mgbean.BeanBuilder.injectResources(BeanBuilder.java:205) 
    ... 37 more 
Caused by: javax.naming.NameNotFoundException: Name com.web.bean.Bond is not bound in this Context 
    at org.apache.naming.NamingContext.lookup(NamingContext.java:770) 
    at org.apache.naming.NamingContext.lookup(NamingContext.java:153) 
    at org.apache.catalina.util.DefaultAnnotationProcessor.lookupFieldResource(DefaultAnnotationProcessor.java:278) 
    at org.apache.catalina.util.DefaultAnnotationProcessor.processAnnotations(DefaultAnnotationProcessor.java:187) 
    at com.sun.faces.vendor.Tomcat6InjectionProvider.inject(Tomcat6InjectionProvider.java:82) 

我的spring配置

<context:annotation-config/> 
<context:component-scan base-package="com.web.bean"/> 

託管bean在那裏我使用註釋

package com.web.bean; 
    @ManagedBean 
    @SessionScoped 

@Resource 
private MailSender mail; 
+0

確定?這不是ejb? – Elbek

回答

0

我已經修復了這個問題,而無需使用@Resource註釋

private MailSender mail = (MailSender) SpringWrapper.getInstance().getBean("mail");