2
回答
jfinal jndi 配置问题
滴滴云服务器,限时包月0.9元,为开发者而生>>>   

@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="\root\tomcat\webapps\xxx" 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

举报
lusheng6323
发帖于2年前 2回/457阅
顶部