javax.naming.OperationNotSupportedException: Can only bind References or Referenceable objects at com.sun.jndi.fscontext.RefFSContext.addObjectToBindings(RefFSContext.java:479) at com.sun.jndi.fscontext.RefFSContext.bindObject(RefFSContext.java:337) at com.sun.jndi.fscontext.RefFSContext.rebind(RefFSContext.java:189)
UT MOCK掉
IT 类似
GOOGLE 关键字 jndi junit
https://stackoverflow.com/questions/12545129/setting-up-jndi-datasource-in-junit
找到了一种,使用commons-dbcp的方式, 官网也给出了一个样例
http://commons.apache.org/proper/commons-dbcp/guide/jndi-howto.html
不过又遇到了下面的这个问题:
原来是少了fscontext依赖, pom文件里添加如下依赖就可以了
不过又报了如下的错误:我感觉我要放弃测试中用jndi了。。
javax.naming.OperationNotSupportedException: Can only bind References or Referenceable objects
at com.sun.jndi.fscontext.RefFSContext.addObjectToBindings(RefFSContext.java:479)
at com.sun.jndi.fscontext.RefFSContext.bindObject(RefFSContext.java:337)
at com.sun.jndi.fscontext.RefFSContext.rebind(RefFSContext.java:189)