NutzCN Logo
问答 NewBe项目访问那是借口出错
发布于 1672天前 作者 qq_6c5a7e9a 1300 次浏览 复制 上一个帖子 下一个帖子
标签:

父类:

@IocBean
public class BaseDao {
	@Inject
	private NutDao dao;

	protected List<JSONObject> getArray(HashMap<String, Object> params) {
		String sqlName = Thread.currentThread().getStackTrace()[2].getClassName()+"."+Thread.currentThread().getStackTrace()[2].getMethodName();
		Sql sql = dao.sqls().create(sqlName);
		for (String name : params.keySet()) {
			sql.setParam(name, params.get(name));
		}
		sql.setEntity(dao.getEntity(JSONObject.class));
		sql.setCallback(Sqls.callback.entities());
		return dao.execute(sql).getList(JSONObject.class);
	}
}

子类:

@IocBean
public class UitilDao extends BaseDao{
	public List<JSONObject> getCantons(boolean getParent) {
		return getArray(new HashMap<String,Object>(){
			private static final long serialVersionUID = 1L;
			{put("getParent", getParent);}
		});
	}
}

错误信息:

Caused by: org.nutz.lang.born.BorningException: Fail to born or cast to 'com.hetaro.dao.UitilDao'
 by args: [@(org.nutz.dao.impl.NutDao@1b5c5290)]
 because: No suitable Constructor or Factory Method!!
	at org.nutz.lang.Mirror.born(Mirror.java:1008)
	at org.nutz.castor.castor.Object2Object.cast(Object2Object.java:12)
	at org.nutz.castor.Castors.cast(Castors.java:252)
	... 55 more
6 回复

贴完整日志

完整的日志:

[WARN ] 15:45:45.244 org.nutz.mvc.impl.processor.FailProcessor.process(FailProcessor.java:28) - Error@/api/util/getCantons :
org.nutz.ioc.IocException: IocBean[utilApi] throw Exception when creating
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:150)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:216)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:245)
	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.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1637)
	at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1637)
	at org.nutz.mvc.WhaleFilter.doFilter(WhaleFilter.java:159)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1637)
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:533)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
	at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:190)
	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1595)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:188)
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1253)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:168)
	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:473)
	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1564)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:166)
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1155)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
	at org.eclipse.jetty.server.Server.handle(Server.java:561)
	at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:334)
	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:251)
	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:279)
	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:104)
	at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:124)
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:247)
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.produce(EatWhatYouKill.java:140)
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:131)
	at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:243)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:679)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:597)
	at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.RuntimeException: IocBean[utilApi] fail at field=[service]
	at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:40)
	at org.nutz.ioc.weaver.DefaultWeaver.fill(DefaultWeaver.java:56)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:136)
	... 44 more
Caused by: org.nutz.ioc.IocException: IocBean[uitilService] throw Exception when creating
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:150)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:216)
	at org.nutz.ioc.impl.NutIoc.getByType(NutIoc.java:407)
	at org.nutz.ioc.val.ReferTypeValue.get(ReferTypeValue.java:66)
	at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:32)
	... 46 more
Caused by: java.lang.RuntimeException: IocBean[uitilService] fail at field=[dao]
	at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:40)
	at org.nutz.ioc.weaver.DefaultWeaver.fill(DefaultWeaver.java:56)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:136)
	... 50 more
Caused by: java.lang.RuntimeException: Fail to set field[com.hetaro.service.UitilService#dao] using value[org.nutz.dao.impl.NutDao@389c6502]
	at org.nutz.lang.inject.InjectByField.inject(InjectByField.java:27)
	at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:33)
	... 52 more
Caused by: org.nutz.castor.FailToCastObjectException: Fail to cast from <org.nutz.dao.impl.NutDao> to <com.hetaro.dao.UitilDao> for {org.nutz.dao.impl.NutDao@389c6502}
	at org.nutz.castor.Castors.cast(Castors.java:262)
	at org.nutz.castor.Castors.castTo(Castors.java:316)
	at org.nutz.lang.inject.InjectByField.inject(InjectByField.java:22)
	... 53 more
Caused by: org.nutz.lang.born.BorningException: Fail to born or cast to 'com.hetaro.dao.UitilDao'
 by args: [@(org.nutz.dao.impl.NutDao@389c6502)]
 because: No suitable Constructor or Factory Method!!
	at org.nutz.lang.Mirror.born(Mirror.java:1008)
	at org.nutz.castor.castor.Object2Object.cast(Object2Object.java:12)
	at org.nutz.castor.Castors.cast(Castors.java:252)
	... 55 more

Fail to set field[com.hetaro.service.UitilService#dao] using value[org.nutz.dao.impl.NutDao@389c6502]

把UitilService的dao属性改名位uitilDao , 或者写成

@Inject("refer:uitilDao")
private UitilDao dao;

这样写,有什么不对吗?

@IocBean
public class UitilService {
	@Inject
	UitilDao dao;

不对
UitilDao 这个类默认生成的ioc 名字是uitilDao
而你定义

@Inject
	UitilDao dao;

他找不到 ioc 中叫 dao 的注入

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