使用JDNI时发生javax.naming.NameNotFoundException: Name is not bound in this Context异常

使用JDNI时发生javax.naming.NameNotFoundException: Name is not bound in this Context异常

在运行tomcat时发现这样的异常,后来在网上查了一下,是数据源没有配好,可能是你没有这个数据源,也可能是你的数据源跟你配置文件上的不对应。后面我检查了一下项目发现我的数据源配置上面写的是java:comp/env/jdbc/flashboard,但是我运行时总是提示name not found。使用JDNI时发生javax.naming.NameNotFoundException: Name is not bound in this Context异常
原来数据源要tomcat里面config文件夹下的context.xm里面配置,如图name里面的属性就是你的数据源,我原来写的是jdbc/cont,跟我配置文件里面写的不一样才会报错,只要将context.xml里面resource标签下的name改成你配置文件上写的名字就好了
使用JDNI时发生javax.naming.NameNotFoundException: Name is not bound in this Context异常