在tomcat conf 下的 server.xml 中的
<Resource name="jdbc/egp"
auth="Container"
type="javax.sql.DataSource"
factory="com.alibaba.druid.pool.DruidDataSourceFactory"
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"
username="root"
password=""
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/egp?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull" />
druid,mysql,的jar包已入到 tomcat/lib下
Tomcat中配置了Realm 使用上面配置的连接池,登录正常,证明OK连接池OK了
<Realm className="org.apache.catalina.realm.DataSourceRealm"
dataSourceName="jdbc/egp" userTable="v_users" userNameCol="user_name"
userCredCol="user_pass" userRoleTable="v_roles" roleNameCol="role_name" />
在nutz IOC中配置 ,jdbc/egp 或 java:/comp/env/jdbc/egp 都有试过
{
"defaultDao": {
"type": "org.nutz.dao.impl.NutDao",
"args": [{"jndi":"jdbc/egp"}]
}
}
调用时报错,
驱动没有载入到?那Realm怎么又OK 的,有请兽叔帮忙看看。。
Caused by: org.nutz.lang.born.BorningException: Fail to born 'org.nutz.dao.impl.NutDao'
by args: [
@(org.apache.tomcat.dbcp.dbcp.BasicDataSource@25685c0e)] becasue:
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'
at org.nutz.lang.born.ConstructorBorning.born(ConstructorBorning.java:19)
at org.nutz.ioc.weaver.DefaultWeaver.born(DefaultWeaver.java:67)
at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:114)
... 34 more
Caused by: org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1452)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
at org.nutz.trans.Trans.getConnectionAuto(Trans.java:263)
at org.nutz.dao.jdbc.Jdbcs.getExpert(Jdbcs.java:106)
at org.nutz.dao.impl.DaoSupport.setDataSource(DaoSupport.java:190)
at org.nutz.dao.impl.DaoSupport.setDataSource(DaoSupport.java:181)
at org.nutz.dao.impl.NutDao.<init>(NutDao.java:113)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.nutz.lang.born.ConstructorBorning.born(ConstructorBorning.java:17)
... 36 more
Caused by: java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getDriver(DriverManager.java:315)
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1437)
... 48 more