NutzCN Logo
问答 使用nutz配置两个数据源进行两个数据库数据的同步,第二个dao报错,请大神赐教!!
发布于 236天前 作者 qq_7a9d9f2d 342 次浏览 复制 上一个帖子 下一个帖子
标签:
var ioc = {
        conf : {
            type : "org.nutz.ioc.impl.PropertiesProxy",
            fields : {
                paths : ["custom/"]
            }
        },
        dataSource : {
            type : "com.alibaba.druid.pool.DruidDataSource",
            events : {
                create : "init",
                depose : 'close'
            },
            fields : {
                url : {java:"$conf.get('db.url')"},
                username : {java:"$conf.get('db.username')"},
                password : {java:"$conf.get('db.password')"},
                testWhileIdle : true,
                validationQuery : {java:"$conf.get('db.validationQuery')"},
                maxActive : {java:"$conf.get('db.maxActive')"}
            }
        },
        dao : {
            type : "org.nutz.dao.impl.NutDao",
            args : [{refer:"dataSource"}]
        },
        dataSourceTongbu : {
            type : "com.alibaba.druid.pool.DruidDataSource",
            events : {
                create : "init",
                depose : 'close'
            },
            fields : {
                url : 'jdbc:sqlserver://127.0.0.1:1433;DatabaseName=att2000',
                username : 'sa',
                password : '有密码',
                testWhileIdle : true,
                validationQuery : 'select 1',
                maxActive : '100'
            }
        },
        daoTongbu : {
            type : "org.nutz.dao.impl.NutDao",
            args : [{refer:"dataSourceTongbu"}]
        }
};

module代码

package cn.webro;

import java.util.List;

import org.nutz.dao.Dao;
import org.nutz.dao.Sqls;
import org.nutz.dao.entity.Record;
import org.nutz.dao.sql.Sql;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Fail;
import org.nutz.mvc.annotation.Ok;

import cn.webro.users.Users;
import cn.webro.users.UsersDAO;
@At("/users")
@Ok("json")
@Fail("http:500")
@IocBean(args={"refer:daoTongbu"})
public class TongbuModule {
	@Inject("daoTongbu")
	//@Inject
	private Dao daoTongbu;
	@Inject
	private UsersDAO usersDAO;
	@At 
	public Object tongbu() {
		String str="select userid id,badgenumber kahao,name xingming,gender xingbie ,ssn haoma from userinfo ";
		Sql sql=Sqls.queryRecord(str);
		daoTongbu.execute(sql);
		List<Record> list=sql.getList(Record.class);
		//List<Users> list2=new ArrayList<Users>();
		for (Record r : list) {
			Users users=new Users();
			users.setId(r.getString("id"));
			users.setKahao(r.getString("kahao"));
			if ("F".equals(r.getString("xingbie"))) {
				users.setXingbie("女");
			}else{
				users.setXingbie("男");
			}
			if("中".equals(r.getString("haoma"))){
				users.setHaoma("小");
			}else{
				users.setHaoma(r.getString("haoma"));
			}
			users.setXingming(r.getString("xingming"));
			usersDAO.save(users);
		}
		System.out.println(123);
		return true;
	}
}

报错信息

2018-04-17 13:21:58,176 [http-bio-8080-exec-1] WARN  org.nutz.mvc.impl.processor.FailProcessor - Error@/users/tongbu :
org.nutz.ioc.IocException: IocBean[tongbuModule] throw Exception when creating
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:152)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:240)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:270)
	at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:116)
	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:202)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at java.lang.Thread.run(Thread.java:744)
Caused by: org.nutz.lang.born.BorningException: Fail to born or cast to 'cn.webro.TongbuModule'
 by args: [@(org.nutz.dao.impl.NutDao@23339129)]
 because: No suitable Constructor or Factory Method!!
	at org.nutz.lang.Mirror.getBorning(Mirror.java:967)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:102)
	... 27 more

5 回复

···
@IocBean(args={"refer:daoTongbu"})
···

args是构造方法参数,然而这个类并没有对应的构造方法

请问该怎么改呢,我在网上百度的。。。

@wendal 请问该怎么改呢,我在网上百度的。。。

@wendal 好尴尬。。。犯这种错误,Ok了。感谢

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