NutzCN Logo
问答 nutzwk注入失败,调用的时候找不到ioc为null
发布于 2315天前 作者 daydayup 2864 次浏览 复制 上一个帖子 下一个帖子
标签: nutzwk
@IocBean
@Component("cmsTccService")
public class CmsTccServiceImpl implements CmsTccService {

    @Inject
    @Reference(check = false)
    private MemberService memberService;


    @Inject
    private CmsTestService cmsTestService;

    private final static Log log = Logs.get();

    @Compensable(confirmMethod = "confirmMakePayment", cancelMethod = "cancelMakePayment")
    public void makePayment(){
        memberService.updateMember(null,1);
        cmsTestService.updateTest(null,1);
    }

    /**
     * 确认付款
     */
    @Aop(TransAop.READ_COMMITTED)
    public void confirmMakePayment() {
        log.info("========================确认付款");
    }


    /**
     * 取消付款
     */
    @Aop(TransAop.READ_COMMITTED)
    public void cancelMakePayment() {
        log.info("========================取消付款");
    }



}
25 回复
public interface CmsTccService {
    public void makePayment();
}

嗯, 你进入了一个困局...

spring ioc 和 nutz ioc的东西并不同时生效

有啥办法可以同时生效么

没有, 但有变通的, 例如

    @Compensable(confirmMethod = "confirmMakePayment", cancelMethod = "cancelMakePayment")
    public void makePayment(){
        if (memberService == null)
            memberService = Mvcs.getIoc().get(MemberService.class);
        if (cmsTestService == null)
            cmsTestService = Mvcs.getIoc().get(CmsTestService.class);
        memberService.updateMember(null,1);
        cmsTestService.updateTest(null,1);
    }

Mvcs.getIoc()这个好像也是null。。

还有, Mvcs.ctx().getDefaultIoc()

但是memberService本地是拿不到的吧,,,他是另一个项目里面

额, dubbo的?

org.nutz.ioc.IocException: IocBean[cmsTestService] For object [cmsTestService] - type:[interface cn.wizzer.app.cms.modules.services.CmsTestService]
	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.cms.modules.services.impl.CmsTccServiceImpl.makePayment(CmsTccServiceImpl.java:41)
	at cn.wizzer.app.cms.modules.services.impl.CmsTccServiceImpl$$FastClassBySpringCGLIB$$e048cf27.invoke(<generated>)
	at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
	at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:717)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
	at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:97)
	at org.mengyun.tcctransaction.interceptor.ResourceCoordinatorInterceptor.interceptTransactionContextMethod(ResourceCoordinatorInterceptor.java:82)
	at org.mengyun.tcctransaction.spring.TccTransactionContextAspect.interceptTransactionContextMethod(TccTransactionContextAspect.java:57)
	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:498)
	at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:621)
	at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:610)
	at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:68)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:168)
	at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
	at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:85)
	at org.mengyun.tcctransaction.interceptor.CompensableTransactionInterceptor.rootMethodProceed(CompensableTransactionInterceptor.java:85)
	at org.mengyun.tcctransaction.interceptor.CompensableTransactionInterceptor.interceptCompensableMethod(CompensableTransactionInterceptor.java:63)
	at org.mengyun.tcctransaction.spring.TccCompensableAspect.interceptCompensableMethod(TccCompensableAspect.java:57)
	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:498)
	at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:621)
	at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:610)
	at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:68)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:168)
	at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:653)
	at cn.wizzer.app.cms.modules.services.impl.CmsTccServiceImpl$$EnhancerBySpringCGLIB$$942a1488.makePayment(<generated>)
	at cn.wizzer.app.cms.modules.services.impl.CmsTestServiceImpl.payment(CmsTestServiceImpl.java:72)
	at com.alibaba.dubbo.common.bytecode.Wrapper2.invokeMethod(Wrapper2.java)
	at com.alibaba.dubbo.rpc.proxy.javassist.JavassistProxyFactory$1.doInvoke(JavassistProxyFactory.java:47)
	at com.alibaba.dubbo.rpc.proxy.AbstractProxyInvoker.invoke(AbstractProxyInvoker.java:76)
	at com.alibaba.dubbo.config.invoker.DelegateProviderMetaDataInvoker.invoke(DelegateProviderMetaDataInvoker.java:52)
	at com.alibaba.dubbo.rpc.protocol.InvokerWrapper.invoke(InvokerWrapper.java:56)
	at com.alibaba.dubbo.rpc.filter.ExceptionFilter.invoke(ExceptionFilter.java:62)
	at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:72)
	at com.alibaba.dubbo.monitor.support.MonitorFilter.invoke(MonitorFilter.java:75)
	at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:72)
	at com.alibaba.dubbo.rpc.filter.TimeoutFilter.invoke(TimeoutFilter.java:42)
	at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:72)
	at com.alibaba.dubbo.rpc.protocol.dubbo.filter.TraceFilter.invoke(TraceFilter.java:78)
	at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:72)
	at com.alibaba.dubbo.rpc.filter.ContextFilter.invoke(ContextFilter.java:72)
	at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:72)
	at com.alibaba.dubbo.rpc.filter.GenericFilter.invoke(GenericFilter.java:131)
	at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:72)
	at com.alibaba.dubbo.rpc.filter.ClassLoaderFilter.invoke(ClassLoaderFilter.java:38)
	at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:72)
	at com.alibaba.dubbo.rpc.filter.EchoFilter.invoke(EchoFilter.java:38)
	at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:72)
	at com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol$1.reply(DubboProtocol.java:103)
	at com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.handleRequest(HeaderExchangeHandler.java:96)
	at com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.received(HeaderExchangeHandler.java:172)
	at com.alibaba.dubbo.remoting.transport.DecodeHandler.received(DecodeHandler.java:51)
	at com.alibaba.dubbo.remoting.transport.dispatcher.ChannelEventRunnable.run(ChannelEventRunnable.java:80)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:748)
Caused by: org.nutz.ioc.ObjectLoadException: Object 'cmsTestService' without define!
	at org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:157)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:195)
	... 64 more

拿本地的ioc也报错

嗯,在MainLaucher里面注入一下, 后续在ioc就能取到了

那问题来了,本地的是可以注入,但是memberService 是另一个dubbo项目,怎么注入,,难道要在cms添加menber模块?

在MainLaucher里面,以dubbo的方式注入,.后续在ioc.get的时候就能取到

不明白为啥你不用tcc-dubbo集成

你是说把服务都放在tcc里面吗?还有就是以dubbo的方式注入,,,这个没试过啊

看来沟通有问题

我也是摸着石头过河。。

如何以dubbo的方式注入。。。

不是有dubbo的demo吗?

就tcc里面的demo

我说的这个,在MainLaucher里面,以dubbo的方式注入,.后续在ioc.get的时候就能取到

把下面代码写到MainLaucher就行

    @Inject
    @Reference(check = false)
    private MemberService memberService;

好像还需要这个

 ioc.addBean("memberService",memberService);
添加回复
请先登陆
回到顶部