NutzCN Logo
问答 Nutz初始化创建User失败
发布于 2236天前 作者 caoliting0924 1382 次浏览 复制 上一个帖子 下一个帖子
标签:
var ioc = {
        dataSource : {
            type : "com.alibaba.druid.pool.DruidDataSource",
            events : {
                create : "init",
                depose : 'close'
            },
            fields : {
                url : "jdbc:mysql://127.0.0.1:3306/nutzbook",
                username : "root",
                password : "root",
                testWhileIdle : true, // 非常重要,预防mysql的8小时timeout问题
                //validationQuery : "select 1" , // Oracle的话需要改成 select 1 from dual
                maxActive : 100
            }
        },
        dao : {
            type : "org.nutz.dao.impl.NutDao",
            args : [{refer:"dataSource"}]
        }
};

日志

2018-11-8 16:36:1.262 DEBUG [localhost-startStop-1] Mysql : character_sets_dir=C:\Program Files\MySQL\MySQL Server 5.5\share\charsets\
2018-11-8 16:36:1.263 DEBUG [localhost-startStop-1] Mysql : binlog_format=STATEMENT
2018-11-8 16:36:1.264 DEBUG [localhost-startStop-1] Mysql : database=nutzbook
2018-11-8 16:36:1.264 DEBUG [localhost-startStop-1] Mysql : user=root@localhost
2018-11-8 16:36:1.276 DEBUG [localhost-startStop-1] Database info --> MYSQL:[MySQL - 5.5.60]
2018-11-8 16:36:1.301 DEBUG [localhost-startStop-1] Found 1 resource by src( com/uss/dao/ ) , regex( ^.+[.]class$ )
18-11-08 16:36:01.328 WARN [localhost-startStop-1] No @Table found, fallback to use table name='user' for type 'net.wendal.nutzbook.bean.User'
2018-11-8 16:36:1.367 DEBUG [localhost-startStop-1] Table 'user' doesn't exist!
2018-11-8 16:36:1.376 DEBUG [localhost-startStop-1] SELECT COUNT(*) FROM user 
2018-11-8 16:36:1.378 DEBUG [localhost-startStop-1] SQLException
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'nutzbook.user' doesn't exist
	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 com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
	at com.mysql.jdbc.Util.getInstance(Util.java:408)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:943)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3970)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3906)
	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2524)
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2677)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2545)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2503)
	at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1369)
	at com.alibaba.druid.pool.DruidPooledStatement.executeQuery(DruidPooledStatement.java:138)
	at org.nutz.dao.impl.sql.run.NutDaoExecutor._runSelect(NutDaoExecutor.java:246)
	at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:53)
	at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:66)
	at org.nutz.dao.impl.interceptor.DaoLogInterceptor.filter(DaoLogInterceptor.java:22)
	at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:64)
	at org.nutz.dao.DaoInterceptorChain.invoke(DaoInterceptorChain.java:139)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.runCallback(NutDaoRunner.java:158)
	at org.nutz.dao.impl.sql.run.NutDaoRunner._runWithoutTransaction(NutDaoRunner.java:125)
	at org.nutz.dao.impl.sql.run.NutDaoRunner._run(NutDaoRunner.java:92)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:81)
	at org.nutz.dao.impl.DaoSupport.run(DaoSupport.java:240)
	at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:248)
	at org.nutz.dao.impl.NutDao.func(NutDao.java:735)
	at org.nutz.dao.impl.NutDao.func(NutDao.java:716)
	at org.nutz.dao.impl.NutDao._count(NutDao.java:703)
	at org.nutz.dao.impl.NutDao.count(NutDao.java:665)
	at net.wendal.nutzbook.MainSetup.init(MainSetup.java:29)
	at org.nutz.mvc.impl.NutLoading.evalSetup(NutLoading.java:277)
	at org.nutz.mvc.impl.NutLoading.load(NutLoading.java:121)
	at org.nutz.mvc.ActionHandler.<init>(ActionHandler.java:19)
	at org.nutz.mvc.NutFilter._init(NutFilter.java:87)
	at org.nutz.mvc.NutFilter.init(NutFilter.java:65)
	at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:285)
	at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:266)
	at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:108)
	at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4747)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5389)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:755)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:731)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717)
	at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1125)
	at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1868)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
18-11-08 16:36:01.379 ERROR [localhost-startStop-1] Error happend during start serivce!
org.nutz.dao.DaoException: !Nutz SQL Error: 'SELECT COUNT(*) FROM user '
PreparedStatement: 
'SELECT COUNT(*) FROM user '
CaseMessage=Table 'nutzbook.user' doesn't exist
	at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:104)
	at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:66)
	at org.nutz.dao.impl.interceptor.DaoLogInterceptor.filter(DaoLogInterceptor.java:22)
	at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:64)
	at org.nutz.dao.DaoInterceptorChain.invoke(DaoInterceptorChain.java:139)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.runCallback(NutDaoRunner.java:158)
	at org.nutz.dao.impl.sql.run.NutDaoRunner._runWithoutTransaction(NutDaoRunner.java:125)
	at org.nutz.dao.impl.sql.run.NutDaoRunner._run(NutDaoRunner.java:92)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:81)
	at org.nutz.dao.impl.DaoSupport.run(DaoSupport.java:240)
	at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:248)
	at org.nutz.dao.impl.NutDao.func(NutDao.java:735)
	at org.nutz.dao.impl.NutDao.func(NutDao.java:716)
	at org.nutz.dao.impl.NutDao._count(NutDao.java:703)
	at org.nutz.dao.impl.NutDao.count(NutDao.java:665)
	at net.wendal.nutzbook.MainSetup.init(MainSetup.java:29)
	at org.nutz.mvc.impl.NutLoading.evalSetup(NutLoading.java:277)
	at org.nutz.mvc.impl.NutLoading.load(NutLoading.java:121)
	at org.nutz.mvc.ActionHandler.<init>(ActionHandler.java:19)
	at org.nutz.mvc.NutFilter._init(NutFilter.java:87)
	at org.nutz.mvc.NutFilter.init(NutFilter.java:65)
	at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:285)
	at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:266)
	at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:108)
	at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4747)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5389)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:755)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:731)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717)
	at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1125)
	at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1868)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'nutzbook.user' doesn't exist
	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 com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
	at com.mysql.jdbc.Util.getInstance(Util.java:408)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:943)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3970)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3906)
	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2524)
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2677)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2545)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2503)
	at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1369)
	at com.alibaba.druid.pool.DruidPooledStatement.executeQuery(DruidPooledStatement.java:138)
	at org.nutz.dao.impl.sql.run.NutDaoExecutor._runSelect(NutDaoExecutor.java:246)
	at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:53)
	... 36 more
18-11-08 16:36:01.379 ERROR [localhost-startStop-1] try to depose ioc
2018-11-8 16:36:1.379 INFO [localhost-startStop-1] org.nutz.ioc.impl.NutIoc@2064463793 is closing. startup date [18-11-08 16:36:00.822]
2018-11-8 16:36:1.379 DEBUG [localhost-startStop-1] Depose object 'dao' ...
2018-11-8 16:36:1.379 DEBUG [localhost-startStop-1] Depose object '$aop_async' ...
2018-11-8 16:36:1.379 DEBUG [localhost-startStop-1] Depose object 'dataSource' ...
十一月 08, 2018 4:36:01 下午 com.alibaba.druid.pool.DruidDataSource info
信息: {dataSource-1} closed
2018-11-8 16:36:1.383 INFO [localhost-startStop-1] org.nutz.ioc.impl.NutIoc@2064463793 is deposed. startup date [18-11-08 16:36:00.822]
十一月 08, 2018 4:36:01 下午 org.apache.catalina.core.StandardContext filterStart
严重: Exception starting filter nutz
org.nutz.mvc.LoadingException: org.nutz.dao.DaoException: !Nutz SQL Error: 'SELECT COUNT(*) FROM user '
PreparedStatement: 
'SELECT COUNT(*) FROM user '
CaseMessage=Table 'nutzbook.user' doesn't exist
	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)
	at org.nutz.lang.born.BornContext.doBorn(BornContext.java:60)
	at org.nutz.lang.Mirror.born(Mirror.java:990)
	at org.nutz.lang.Lang.wrapThrow(Lang.java:197)
	at org.nutz.mvc.impl.NutLoading.load(NutLoading.java:135)
	at org.nutz.mvc.ActionHandler.<init>(ActionHandler.java:19)
	at org.nutz.mvc.NutFilter._init(NutFilter.java:87)
	at org.nutz.mvc.NutFilter.init(NutFilter.java:65)
	at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:285)
	at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:266)
	at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:108)
	at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4747)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5389)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:755)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:731)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717)
	at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1125)
	at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1868)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Caused by: org.nutz.dao.DaoException: !Nutz SQL Error: 'SELECT COUNT(*) FROM user '
PreparedStatement: 
'SELECT COUNT(*) FROM user '
CaseMessage=Table 'nutzbook.user' doesn't exist
	at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:104)
	at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:66)
	at org.nutz.dao.impl.interceptor.DaoLogInterceptor.filter(DaoLogInterceptor.java:22)
	at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:64)
	at org.nutz.dao.DaoInterceptorChain.invoke(DaoInterceptorChain.java:139)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.runCallback(NutDaoRunner.java:158)
	at org.nutz.dao.impl.sql.run.NutDaoRunner._runWithoutTransaction(NutDaoRunner.java:125)
	at org.nutz.dao.impl.sql.run.NutDaoRunner._run(NutDaoRunner.java:92)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:81)
	at org.nutz.dao.impl.DaoSupport.run(DaoSupport.java:240)
	at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:248)
	at org.nutz.dao.impl.NutDao.func(NutDao.java:735)
	at org.nutz.dao.impl.NutDao.func(NutDao.java:716)
	at org.nutz.dao.impl.NutDao._count(NutDao.java:703)
	at org.nutz.dao.impl.NutDao.count(NutDao.java:665)
	at net.wendal.nutzbook.MainSetup.init(MainSetup.java:29)
	at org.nutz.mvc.impl.NutLoading.evalSetup(NutLoading.java:277)
	at org.nutz.mvc.impl.NutLoading.load(NutLoading.java:121)
	... 19 more
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'nutzbook.user' doesn't exist
	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 com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
	at com.mysql.jdbc.Util.getInstance(Util.java:408)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:943)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3970)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3906)
	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2524)
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2677)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2545)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2503)
	at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1369)
	at com.alibaba.druid.pool.DruidPooledStatement.executeQuery(DruidPooledStatement.java:138)
	at org.nutz.dao.impl.sql.run.NutDaoExecutor._runSelect(NutDaoExecutor.java:246)
	at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:53)
	... 36 more
十一月 08, 2018 4:36:01 下午 org.apache.catalina.core.StandardContext startInternal

package net.wendal.nutzbook; import java.util.Date; import org.nutz.dao.Dao; import org.nutz.dao.util.Daos; import org.nutz.ioc.Ioc; import org.nutz.mvc.NutConfig; import org.nutz.mvc.Setup; import net.wendal.nutzbook.bean.User; /** * @author: Alan * @date:2018年11月8日 下午3:52:20 * @version : * */ public class MainSetup implements Setup{ // 注意是init方法,不是destroy方法 public void init(NutConfig nc) { Ioc ioc = nc.getIoc(); Dao dao = ioc.get(Dao.class); // 如果提示没有createTablesInPackage方法,请确认用了最新版的nutz,且老版本的nutz已经删除干净 Daos.createTablesInPackage(dao, "com.uss.dao", false); // 初始化默认根用户 if (dao.count(User.class) == 0) { User user = new User(); user.setName("admin"); user.setPassword("123456"); user.setCreateTime(new Date()); user.setUpdateTime(new Date()); dao.insert(user); } } public void destroy(NutConfig nc) { } }
6 回复

nutz-1.r.60 版本

2018-11-8 16:36:1.301 DEBUG [localhost-startStop-1] Found 1 resource by src( com/uss/dao/ ) , regex( ^.+[.]class$ )
18-11-08 16:36:01.328 WARN [localhost-startStop-1] No @Table found, fallback to use table name='user' for type 'net.wendal.nutzbook.bean.User'

你的package到底是哪个? com.uss.dao 还是 net.wendal.nutzbook

社区群找蛋蛋,免费提供远程服务

这个是原来没有改动的时候,报的错;同样初始化没有成功,我在社区找相关的问题解答也没有找到原因

2018-11-9 8:55:59.290 DEBUG [localhost-startStop-1] Found 3 resource by src( net/wendal/nutzbook/ ) , regex( ^.+[.]class$ )
18-11-09 08:55:59.316 WARN [localhost-startStop-1] No @Table found, fallback to use table name='user' for type 'net.wendal.nutzbook.bean.User'
2018-11-9 8:55:59.355 DEBUG [localhost-startStop-1] Table 'user' doesn't exist!
2018-11-9 8:55:59.364 DEBUG [localhost-startStop-1] SELECT COUNT(*) FROM user 
2018-11-9 8:55:59.367 DEBUG [localhost-startStop-1] SQLException
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'nutzbook.user' doesn't exist
	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)

User类没加@Table注解?

来自炫酷的 NutzCN

对,没有加@Table(""t_user)注解,没有看到=-=!

添加回复
请先登陆
回到顶部