javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
問題
JSF 2.0 WebアプリケーションであるマネージドBeanは、@Resource
を使用して「jdbc/exampledb
」データソースをdsプロパティに挿入します。
@ManagedBean(name="customer") @SessionScoped public class CustomerBean implements Serializable{ //resource injection @Resource(name="jdbc/exampledb") private DataSource ds;
Tomcat 6にデプロイすると、MySQLデータソース設定に関する次のエラーメッセージがヒットします。
com.sun.faces.mgbean.ManagedBeanCreationException: An error occurred performing resource injection on managed bean customer at com.sun.faces.mgbean.BeanBuilder.injectResources(BeanBuilder.java:207) Caused by: com.sun.faces.spi.InjectionProviderException: javax.naming.NameNotFoundException: Name jdbc 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:201) ... 53 more Caused by: javax.naming.NameNotFoundException: Name jdbc is not bound in this Context at org.apache.naming.NamingContext.lookup(NamingContext.java:770) at org.apache.naming.NamingContext.lookup(NamingContext.java:153) ... 54 more
溶液
「jdbc / exampledb」データソースがTomcatで正しく構成されていません。詳細については、このガイドを参照してください–How to configure MySQL DataSource in Tomcat 6