大家好,请教一下各位,今天我在用nutz整合dubbo的时候参考
http://git.oschina.net/nutz/nutzmore/tree/master/nutz-integration-dubbo
配置已经成功,但是要把生产者配置在xml里面才能用。
我想请教一下,如何不配置在xml里面而是使用Reference来使用呢。
看了一下源代码AnnotationBean.java,是处理了注解的,我配置了,但是没生效。求助各位,谢谢!
7 回复
不行,我就是试过了。
@IocBean
@At("/billing")
public class BillingService {
private static final Log log = Logs.get();
@Inject("refer:billingExtractService")
protected IBillingExtractService billingExtractService;
@Inject
@Reference
protected IAtomRuleService atomRuleService;
@At("/processBillOrder")
public Object processBillOrder(@Param("phoneNumber") String phoneNumber, @Param("activityId") String activityId, HttpSession session) {
log.info("哈哈atomRuleService" + atomRuleService);
return billingExtractService.processBillOrder("test msg");
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<dubbo:application name="ruleweb"/>
<dubbo:registry address="zookeeper://10.43.161.14:2181" protocol="dubbo"/>
<dubbo:annotation package="com.ai.rule.web.service"/>
<dubbo:reference id="billingExtractService"
interface="com.ai.rule.api.billing.extract.dobbo.IBillingExtractService" timeout="10000"/>
</beans>
@Ok("json:full")
@SetupBy(value = MainSetup.class)
@IocBy(type = ComboIocProvider.class, args = {
"*anno", "com.ai.rule.web",
"*dubbo", "dubbo-client.xml"})
@Modules
public class MainModule {
}
public class MainSetup implements Setup {
@Override
public void init(NutConfig nc) {
Ioc ioc = nc.getIoc();
ioc.get(DubboManager.class);
}
@Override
public void destroy(NutConfig nc) {
}
}
billingExtractService能注入进来,atomRuleService就不行,日志如下:
2017-09-17 19:38:35,162 org.nutz.mvc.impl.processor.FailProcessor.process(FailProcessor.java:28) WARN - Error@/billing/processBillOrder :
org.nutz.ioc.IocException: IocBean[billingService] throw Exception when creating
at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:149)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:210)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:239)
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:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:506)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:962)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1115)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.RuntimeException: IocBean[billingService] fail at field=[atomRuleService]
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:135)
... 28 more
Caused by: org.nutz.ioc.IocException: IocBean[class:com.ai.rule.api.dubbo.service.IAtomRuleService] none ioc bean match class=com.ai.rule.api.dubbo.service.IAtomRuleService
at org.nutz.ioc.impl.NutIoc.getByType(NutIoc.java:399)
at org.nutz.ioc.val.ReferTypeValue.get(ReferTypeValue.java:66)
at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:32)
... 30 more
添加回复
请先登陆