NutzCN Logo
问答 关于view的service注入问题
发布于 2173天前 作者 木易 1948 次浏览 复制 上一个帖子 下一个帖子
标签:

我的POJO

@View("Cai_sample_view")
@Data
public class Cai_sample_view implements Serializable{
    private static final long serialVersionUID = 1L;


    @Column
    @Comment("样品记录Id")
    @ColDefine(type= ColType.VARCHAR, width = 32)
    private String id;
}

我的service和impl

public interface CaiSampleViewService extends BaseService<Cai_sample_view> {

}


@IocBean(args = {"refer:dao"})
@Service(interfaceClass=CaiSampleViewService.class)
public class CaiSampleViewServiceImpl extends BaseServiceImpl<Cai_sample_view> implements CaiSampleViewService {
    public CaiSampleViewServiceImpl(Dao dao) {
        super(dao);
    }
}

当我尝试注入

    @Inject
    @Reference
    private CaiSampleViewService caiSampleViewService;

出现异常

org.nutz.ioc.IocException: IocBean[sampleController] 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.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at cn.wizzer.app.web.commons.processor.GlobalsSettingProcessor.process(GlobalsSettingProcessor.java:49)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at cn.wizzer.app.web.commons.processor.LogTimeProcessor.process(LogTimeProcessor.java:21)
	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:1610)
	at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61)
	at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)
	at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)
	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
	at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
	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:1610)
	at cn.wizzer.app.web.commons.filter.RouteFilter.doFilter(RouteFilter.java:31)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1610)
	at org.nutz.mvc.WhaleFilter.doFilter(WhaleFilter.java:171)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1602)
	at org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter.doFilter(WebSocketUpgradeFilter.java:214)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1610)
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:540)
	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:1588)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255)
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1345)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:203)
	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:480)
	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1557)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:201)
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1247)
	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:502)
	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[sampleController] fail at field=[caiSampleViewService]
	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)
	... 59 more
Caused by: org.nutz.ioc.IocException: IocBean[class:cn.wizzer.app.cai.modules.services.CaiSampleViewService] none ioc bean match class=cn.wizzer.app.cai.modules.services.CaiSampleViewService
	at org.nutz.ioc.impl.NutIoc.getByType(NutIoc.java:461)
	at org.nutz.ioc.val.ReferTypeValue.get(ReferTypeValue.java:66)
	at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:32)
	... 61 more
17 回复

CaiSampleViewServiceImpl在同一个maven 模块里面?

没有,我之前用插件生成的service和impl也出现这个问题,不在同一模板

我刚刚查看,CaiSampleViewServiceImpl确实是创建成功的,
在我尝试,出现异常

CaiSampleService caiSampleService = ioc.get(CaiSampleService.class);
org.nutz.ioc.IocException: IocBean[dubboRpcCaiMainLauncher -> caiSampleService] For object [caiSampleService] - type:[interface cn.wizzer.app.cai.modules.services.CaiSampleService]
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:250)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:271)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:161)
	at cn.wizzer.app.cai.commons.core.DubboRpcCaiMainLauncher.init(DubboRpcCaiMainLauncher.java:56)
	at cn.wizzer.app.cai.commons.core.DubboRpcCaiMainLauncher$FM$init$cff301be46c87e2fbea60f4ef344bacb.invoke(DubboRpcCaiMainLauncher.java)
	at org.nutz.ioc.impl.ObjectMakerImpl$2.trigger(ObjectMakerImpl.java:180)
	at org.nutz.ioc.weaver.DefaultWeaver.onCreate(DefaultWeaver.java:89)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:141)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:241)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:271)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:161)
	at org.nutz.boot.NbApp.execute(NbApp.java:210)
	at org.nutz.boot.NbApp.run(NbApp.java:178)
	at cn.wizzer.app.cai.commons.core.DubboRpcCaiMainLauncher.main(DubboRpcCaiMainLauncher.java:51)
Caused by: org.nutz.ioc.ObjectLoadException: Object 'caiSampleService' without define!
	at org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:157)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:195)
	... 13 more

如果不在同一个模块,那么所在模块启动后,才能启动当前模块,不然拿不到实例的

我启动过这个模板了,但是在web模板中还是取不到值

ioc.get是肯定拿不到的

那我怎么做才能在web注入进去呢
这是Controller的注入,但是,注入时就会出现错误

    @Inject
    @Reference
    private CaiSampleViewService caiSampleViewService;

先确定CaiSampleViewServiceImpl被扫描到, 被创建, 而且dubbo日志里面有出现他

日志里面只有两行说明

[INFO ] 17:25:34.853 org.nutz.ioc.loader.annotation.AnnotationIocLoader.addClass(AnnotationIocLoader.java:99) -    > add 'caiSampleServiceImpl                    ' - cn.wizzer.app.cai.modules.services.impl.CaiSampleServiceImpl

[DEBUG] 17:25:36.900 org.nutz.ioc.loader.combo.ComboIocLoader.printFoundIocBean(ComboIocLoader.java:226) - Found IocObject(caiSampleServiceImpl) in AnnotationIocLoader(packages=[cn.wizzer])

跟其他@Service类对比一下,看看差了些什么吧

dubbo日志里面有出现,但是,web里面没有办法注入

[INFO ] 17:25:38.759 com.alibaba.dubbo.config.ServiceConfig.exportLocal(ServiceConfig.java:539) -  [DUBBO] Export dubbo service cn.wizzer.app.cai.modules.services.CaiSampleViewService to local registry, dubbo version: 2.6.5, current host: 192.168.10.34

我看了一下dubbo日志,在服务端,确实已经注入了的,但是在消费端,我就没有看见

@qq_32b899df 万分感谢

... 类重名了呀?

哇塞,蛋蛋还提供远程服务!!!

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