jfinal jndi 配置问题

发布于 2021-11-29 22:24:05 字数 5698 浏览 755 评论 1

@JFinal 你好,想跟你请教个问题:

2015-11-01 14:20:30
[INFO]-[Thread: RMI TCP Connection(3)-127.0.0.1]-[com.xxx.config.xxxConfig.configPlugin()]: java:comp/env/jdbc/xxx1.1.0连接池启动成功!
2015-11-01 14:20:30
[ERROR]-[Thread: RMI TCP Connection(3)-127.0.0.1]-[com.jfinal.core.Config.startPlugins()]: Plugin start error: com.jfinal.plugin.activerecord.ActiveRecordPlugin. 
java.sql.SQLException: Cannot create JDBC driver of class '' for connect URL 'null'
com.jfinal.plugin.activerecord.ActiveRecordException: java.sql.SQLException: Cannot create JDBC driver of class '' for connect URL 'null'
at com.jfinal.plugin.activerecord.TableBuilder.build(TableBuilder.java:91)
at com.jfinal.plugin.activerecord.ActiveRecordPlugin.start(ActiveRecordPlugin.java:171)
at com.jfinal.core.Config.startPlugins(Config.java:87)
at com.jfinal.core.Config.configJFinal(Config.java:48)
at com.jfinal.core.JFinal.init(JFinal.java:65)
at com.jfinal.core.JFinalFilter.init(JFinalFilter.java:49)
at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:279)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:260)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:105)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4574)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5193)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717)
at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1648)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:463)
at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:413)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1466)
at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76)

代码:

//配置数据源
DataSource datasource = null;
try {
datasource = (DataSource)new InitialContext().lookup(getProperty("datasource"));
} catch (NamingException e) {
log.error(getProperty("datasource") + "  数据库连接失败!!!" + e.getMessage());
}
log.info(getProperty("datasource") + "连接池启动成功!");
ActiveRecordPlugin arp = new ActiveRecordPlugin(datasource);
//开发模式
arp.setDevMode(getPropertyToBoolean("devMode"));
//显示SQL
arp.setShowSql(getPropertyToBoolean("showSql"));
//数据库为mySql
arp.setDialect(new com.jfinal.plugin.activerecord.dialect.MysqlDialect());
/**
 * 加载数据库MODE
 */
arp.addMapping("user_base", com.xxx.model.User.class);
me.add(arp);

配置文件1(在tomcat/conf/server.xml中):

<Context path="" docBase="roottomcatwebappsxxx" privileged="true" antiResourceLocking="false" antiJARLocking="false" reloadable="true">
<Resource name="jdbc/xxx1.1.0"
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="******"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/xxx1.1.0?characterEncoding=UTF-8"/>
</Context>
配置文件2(web.xml):

<resource-ref>
<description>mySql Datasource</description>
<res-ref-name>jdbc/xxx1.1.0</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
另外说明:在web-inf/lib和tomcat/中均添加了mysql-connector-java-5.1.35-bin.jar

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不再见 2021-11-30 12:14:58

   异常提示是 driver class 为 null 值,所以检查一下配置,配置文件中的 "
driverClassName" 或许应该改成 driverClass,直到改对不提示 driver class 为 null 为止,可以确定的是,目前的异常出现在 JNDI 配置之中

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文