Main Tutorials

javax.naming.NameNotFoundException: Name jdbc is not bound in this Context

Problem

JSF 2.0 web application, a managed bean uses @Resource to inject the “jdbc/mkyongdb” datasource into a ds property.


@ManagedBean(name="customer")
@SessionScoped
public class CustomerBean implements Serializable{
 
	//resource injection
	@Resource(name="jdbc/mkyongdb")
	private DataSource ds;

When deployed to Tomcat 6, it hits following error messages for the MySQL datasource configuration.


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

Solution

The “jdbc/mkyongdb” datasource is not configure properly in Tomcat, see this guide for detail – How to configure MySQL DataSource in Tomcat 6

About Author

author image
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

Subscribe
Notify of
1 Comment
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Ernesto Sabquet
5 years ago

wso2 how I can resolve the problem java.lang.RuntimeException: Error in looking up data source: Name [postgres] is not bound in this Context. Unable to find [postgres].