NutzCN Logo
问答 nutzboot启动,不注入dao是怎么回事
发布于 39天前 作者 文涛 140 次浏览 复制 上一个帖子 下一个帖子
标签:

使用的最新的nutzboot,我在NutDaoStarter的getDao方法打了断点都不进来,很奇怪

org.nutz.ioc.IocException: IocBean[iptv] throw Exception when creating
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:152)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:241)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:271)
	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:1642)
	at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
	at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
	at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
	at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
	at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
	at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1642)
	at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1642)
	at org.nutz.mvc.WhaleFilter.doFilter(WhaleFilter.java:171)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1634)
	at org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter.doFilter(WebSocketUpgradeFilter.java:215)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1642)
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:533)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:146)
	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:257)
	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1595)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255)
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1340)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:203)
	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:201)
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1242)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:144)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
	at org.eclipse.jetty.server.Server.handle(Server.java:503)
	at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:364)
	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:260)
	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:305)
	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)
	at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:118)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:765)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:683)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.RuntimeException: IocBean[iptv] fail at field=[productService]
	at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:40)
	at org.nutz.ioc.weaver.DefaultWeaver.fill(DefaultWeaver.java:67)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:138)
	... 50 more
Caused by: org.nutz.ioc.IocException: IocBean[productService] throw Exception when creating
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:152)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:241)
	at org.nutz.ioc.val.ReferTypeValue.get(ReferTypeValue.java:60)
	at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:32)
	... 52 more
Caused by: java.lang.RuntimeException: IocBean[productService] fail at field=[ltDao]
	at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:40)
	at org.nutz.ioc.weaver.DefaultWeaver.fill(DefaultWeaver.java:67)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:138)
	... 55 more
Caused by: org.nutz.ioc.IocException: IocBean[ltDao] For object [ltDao] - type:[]
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:250)
	at org.nutz.ioc.val.ReferValue.get(ReferValue.java:24)
	at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:32)
	... 57 more
Caused by: org.nutz.ioc.ObjectLoadException: Object 'ltDao' without define!
	at org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:157)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:195)
	... 59 more
20 回复

getDao 和 injectManyDao 都没进来

知道了,必须要先使用默认的dao,才可以注入其他的dao

但是我发现many的多注入貌似还是有问题,会注入jdbc.为前缀的

@wendal 请问DataSourceStater里的这段 case "com.alibaba.druid.pool.DruidDataSource": 是不是始终只取同一个DataSource

public static DataSource createDataSource(Ioc ioc, PropertiesProxy conf, String prefix) {
        switch (conf.get(prefix + "type", "druid")) {
        case "simple":
        case "org.nutz.dao.impl.SimpleDataSource":
            SimpleDataSource simpleDataSource = new SimpleDataSource();
            String jdbcUrl = conf.get(PRE + "jdbcUrl", conf.get(PRE + "url"));
            if (Strings.isBlank(jdbcUrl)) {
                throw new RuntimeException("need " + PRE + ".url");
            }
            simpleDataSource.setJdbcUrl(jdbcUrl);
            simpleDataSource.setUsername(conf.get(PROP_USERNAME));
            simpleDataSource.setPassword(conf.get(PROP_PASSWORD));
            return simpleDataSource;
        case "druid":
        case "com.alibaba.druid.pool.DruidDataSource":
            DataSource ds = ioc.get(DataSource.class, "druidDataSource");
            String[] tmp = ioc.getNamesByType(DruidPasswordCallback.class);
            for (String beanName : tmp) {
				if (!Strings.isBlank(beanName))
					((DruidDataSource)ds).setPasswordCallback(ioc.get(DruidPasswordCallback.class, beanName));
			}
            return ds;
        case "hikari":
        case "com.zaxxer.hikari.HikariDataSource":
            return ioc.get(DataSource.class, "hikariDataSource");
        default:
            break;
        }

知道了,看来DataSourceStarter也要改下才能支持many的注入

期待你的修改,我暂时没有多数据源的场景

正在改,等下就提交

@wendal 已提交,麻烦审核下

请问多久可以mvn -U

大概10分钟

吼吼,美得很,问题完美解决

@wendal 只是还有一个不太科学的问题,那就是必须要先注入默认的dao,才会触发manyDao的注入,有没有什么方法可以规避

因为你写在getDao方法里面了

你可以这样试试

@IocBean(create="init")
public class NutDaoStarter {

     public void init() {
         injectManyDao();
     }

然后getDao方法里面就不要调用injectManyDao()了

不知道void方法是否可以注解iocbean,如果可以,我就把injectManyDao直接从getDao方法里抽取出来

不能的... 那样行不通的

按你说的方式提交了

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