NutzCN Logo
问答 postgresql,数据库连接错误
发布于 2902天前 作者 老司机 2376 次浏览 复制 上一个帖子 下一个帖子
标签:

首先,这个项目不是通过读取js文件获得dao的,是通过后期加入的,并且是两个数据库连接

 private void setDao(UserConf userconf, Ioc ioc, SimpleDataSource source) throws ClassNotFoundException {
        source.setJdbcUrl(
                "jdbc:postgresql://" + userconf.getDbservername() + ":" + userconf.getDbserverport() + "/smartdc");
        NutDao dao = new NutDao(source);
        ((Ioc2) ioc).getIocContext().save("app", "dao", new ObjectProxy(dao));
    }

    private void setDCMDao(UserConf userconf, Ioc ioc, SimpleDataSource source) throws Exception {
        source.setJdbcUrl(
                "jdbc:postgresql://" + userconf.getDbservername() + ":" + userconf.getDbserverport() + "/dcm");
        NutDao dcmDao = new NutDao(source);
//        dcmDao.execute(Sqls.create("CREATE DATABASE smartdc;"));
        ((Ioc2) ioc).getIocContext().save("app", "dcmDao", new ObjectProxy(dcmDao));
    }

但是,在后面用到的时候

@IocBean
public class EntityDao extends BaseDao {
    @Inject(value = "dcmDao")
    Dao dcmDao;

debug

 Sql sql1 = Sqls.create("SELECT tablename FROM pg_tables WHERE tablename NOT LIKE 'pg%' AND tablename NOT LIKE 'sql_%' ORDER BY tablename;");
        sql1.setCallback(Sqls.callback.strs());
        dcmDao.execute(sql1);
        String[] tableNames = sql1.getObject(String[].class);
        Log log = Logs.get();
        log.debug(Json.toJson(tableNames));

发现所列表名均为另一个dao的表名,并非我想要的dcmDao,也就是说注入错误?请问怎么解决

5 回复

想动态替换?

@wendal 不是动态替换,是启动后注入,我们是给另外一个项目添加后台,需要操作它的数据库,所以我们的项目没有dao.js,项目启动后解析它的配置文件再注入dao

打印一下dcmDao.hashcode

@wendal

 log.debug(dcmDao.hashCode());

?就是一数字啊2113205369

@wendal 在新建dcmDao的时候报错,日志

2016-12-05 17:13:42,766 org.nutz.dao.impl.SimpleDataSource.<init>(SimpleDataSource.java:33) WARN  - SimpleDataSource is NOT a Connection Pool, So it is slow but safe for debug/study
2016-12-05 17:13:42,782 org.nutz.dao.impl.NutDao.<init>(NutDao.java:108) DEBUG - NutDao[_selfId=0] init ...
2016-12-05 17:13:42,796 org.nutz.filepool.NutFilePool.<init>(NutFilePool.java:23) INFO  - Init file-pool by: /home/dcm/.nutz/tmp/dao/ [200000]
2016-12-05 17:13:42,845 org.nutz.lang.Files.createDirIfNoExists(Files.java:422) WARN  - create filepool dir(/home/dcm/.nutz/tmp/dao) fail!!
2016-12-05 17:13:42,846 org.nutz.dao.jdbc.JdbcExpertConfigFile.init(JdbcExpertConfigFile.java:66) WARN  - NutDao FilePool create fail!! Blob and Clob Support is DISABLE!! Home=/home/dcm/.nutz/tmp/dao/
java.lang.RuntimeException: '/home/dcm/.nutz/tmp/dao/' should be a directory or don't have permission to create it!
        at org.nutz.lang.Lang.makeThrow(Lang.java:133)
        at org.nutz.lang.Files.createDirIfNoExists(Files.java:426)
        at org.nutz.filepool.NutFilePool.<init>(NutFilePool.java:27)
        at org.nutz.dao.jdbc.JdbcExpertConfigFile.init(JdbcExpertConfigFile.java:48)
        at org.nutz.dao.jdbc.Jdbcs.<clinit>(Jdbcs.java:73)
        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 com.amax.service.ToolsService.setDCMDao(ToolsService.java:119)
        at com.amax.service.ToolsService.getUserConf(ToolsService.java:101)
        at com.amax.module.ToolsModule.init(ToolsModule.java:33)
        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.nutz.mvc.impl.processor.MethodInvokeProcessor.process(MethodInvokeProcessor.java:25)
        at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
        at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:33)
        at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
        at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:58)
        at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
        at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:123)
        at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
        at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
        at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
        at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
        at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
        at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
        at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
        at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:198)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:620)
        at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.lang.Thread.run(Thread.java:745)
2016-12-05 17:13:42,857 org.nutz.dao.jdbc.Jdbcs.<clinit>(Jdbcs.java:90) DEBUG - Jdbcs init complete
2016-12-05 17:13:42,857 org.nutz.dao.jdbc.Jdbcs.getExpert(Jdbcs.java:103) INFO  - Get Connection from DataSource for JdbcExpert, if I lock at here, check your database server and configure
2016-12-05 17:13:42,975 org.nutz.dao.impl.DaoSupport$1.invoke(DaoSupport.java:200) DEBUG - JDBC Driver --> PostgreSQL 9.4.1211.jre7
2016-12-05 17:13:42,975 org.nutz.dao.impl.DaoSupport$1.invoke(DaoSupport.java:201) DEBUG - JDBC Name   --> PostgreSQL Native Driver
2016-12-05 17:13:42,976 org.nutz.dao.impl.DaoSupport$1.invoke(DaoSupport.java:203) DEBUG - JDBC URL    --> jdbc:postgresql://localhost:6443/dcm
2016-12-05 17:13:42,976 org.nutz.dao.impl.DaoSupport.setDataSource(DaoSupport.java:247) DEBUG - Database info --> PSQL:[PostgreSQL - 9.3.5]
2016-12-05 17:13:42,982 org.nutz.ioc.impl.ScopeContext.save(ScopeContext.java:64) DEBUG - Save object 'dcmDao' to [app]

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