0

我试图使用 spring @Resource Annotation 将 util 类注入托管 bean,但是当我运行应用程序时,我得到了这个错误。

    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)

我的弹簧配置

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

我使用注释的托管bean

  package com.web.bean;
  @ManagedBean
  @SessionScoped

@Resource
private MailSender mail;
4

1 回答 1

0

我在不使用@Resource Annotation 的情况下解决了这个问题

private MailSender mail = (MailSender) SpringWrapper.getInstance().getBean("mail");
于 2012-10-08T03:08:45.310 回答