开发者社区> 问答> 正文

jfinal使用JDNI方式连接数据库么,试了老是报错,求一个详细点的,?报错

jfinal使用JDNI方式连接数据库么,试了老是报错,求一个详细点的。用的是Tomcat jdbc pool连接池。

稍后我把配置贴出来。

DataSource datasource = (DataSource)new InitialContext().lookup("java:jdbc/infor_jdbc_DB");
   ActiveRecordPlugin arp = new ActiveRecordPlugin(datasource);  // 配置ActiveRecord插件
   arp.addMapping("blog", Blog.class); // 映射blog 表到 Blog模型
   me.add(arp); 
<?xml version="1.0" encoding="UTF-8"?>
<Context>
	<Resource name="jdbc/infor_jdbc_DB"
      auth="Container"

      type="javax.sql.DataSource"
      factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
      testWhileIdle="true"
      testOnBorrow="true"
      testOnReturn="false"

      validationQuery="SELECT 1"
      validationInterval="30000"
      timeBetweenEvictionRunsMillis="30000"
      maxActive="100"
      minIdle="10"

      maxWait="10000"
      initialSize="10"
      removeAbandonedTimeout="60"
      removeAbandoned="true"
      logAbandoned="true"

      minEvictableIdleTimeMillis="30000"
      jmxEnabled="true"
      jdbcInterceptors=
"org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer"
      username="root"
      password="123456"

      driverClassName="com.mysql.jdbc.Driver"
      url="jdbc:mysql://localhost:3306/jfinal_demo"/>
</Context>

信息: Starting Servlet Engine: Apache Tomcat/6.0.37
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)
 at org.apache.naming.SelectorContext.lookup(SelectorContext.java:152)
 at javax.naming.InitialContext.lookup(InitialContext.java:392)
 at com.demo.common.DemoConfig.configPlugin(DemoConfig.java:60)
 at com.jfinal.core.Config.configJFinal(Config.java:48)
 at com.jfinal.core.JFinal.init(JFinal.java:68)
 at com.jfinal.core.JFinalFilter.init(JFinalFilter.java:49)
 at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:295)
 at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:424)
 at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:115)
 at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4072)
 at org.apache.catalina.core.StandardContext.start(StandardContext.java:4726)
 at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
 at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
 at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
 at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
 at org.apache.catalina.core.StandardService.start(StandardService.java:525)
 at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
 at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:597)
 at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
 at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
2014-4-3 11:32:52 org.apache.coyote.http11.Http11Protocol start
信息: Starting Coyote HTTP/1.1 on http-8080
2014-4-3 11:32:52 org.apache.jk.common.ChannelSocket init
信息: JK: ajp13 listening on /0.0.0.0:8009
2014-4-3 11:32:52 org.apache.jk.server.JkMain start
信息: Jk running ID=0 time=0/62  config=null
2014-4-3 11:32:52 org.apache.catalina.startup.Catalina start
信息: Server startup in 1297 ms

按照网上在web添加的都试了。不行。

 

 


展开
收起
爱吃鱼的程序员 2020-06-22 11:07:51 429 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    以下ActiveRecordPlugin使用JNDI的例子:

    DataSourcedatasource=(DataSource)newInitialContext().lookup("java:MySqlDs");ActiveRecordPluginarp=newActiveRecordPlugin(datasource);arp.addMapping("user",User.class);plugins.add(arp);

    2020-06-22 11:08:09
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
DTCC 2022大会集锦《云原生一站式数据库技术与实践》 立即下载
阿里云瑶池数据库精要2022版 立即下载
2022 DTCC-阿里云一站式数据库上云最佳实践 立即下载