NutzCN Logo
问答 Nutz怎么加载ProtoBuf插件啊 有没有例子,好难懂
发布于 3018天前 作者 qq_3c29d04b 1646 次浏览 复制 上一个帖子 下一个帖子
标签:

找不到合适的工程,根本不知道怎么写

27 回复

里面有2种实现, 原生proto和jproto, 不过配置起来大同小异

插件本身已经有说明了,哪个地方不明白呢?

https://github.com/nutzam/nutzmore/tree/master/nutz-plugins-protobuf

这是action

@At
	@Ok("ioc:proto")
	@AdaptBy(type = ProtobufAdaptor.class, args = { "ioc:protobufAdaptor" })
	public Message proto(Message message, @Attr("messageType") short messageType) {
		return message;
	}

	@At
	@Ok("ioc:jproto")
	@AdaptBy(type = JProtobufAdaptor.class, args = { "ioc:jprotobufAdaptor" })
	public Message jproto(Message message, @Attr("messageType") short messageType) {
		return message;
	}

	@At
	@Ok("ioc:jproto")
	@AdaptBy(type = JProtobufAdaptor.class, args = { "ioc:jprotobufAdaptor" })
	public UserJProtoBufProtoClass jprotoa(UserJProtoBufProtoClass message) {
		return message;
	}

	@At
	@Ok("raw")
	public String test() {
		Codec<UserJProtoBufProtoClass> codec = ProtobufProxy.create(UserJProtoBufProtoClass.class);
		System.out.println(codec);
		return "msg";
	}

这是请求

public static void main1(String[] args) {
		UserProto.User user = UserProto.User.newBuilder().setId(1).setName("zhangsan").build();
		byte[] bytes = user.toByteArray().clone();
		String url = "http://127.0.0.1:8080/nutz_buff/proto";
		Request req = Request.create(url, METHOD.POST);
		req.getHeader().set("Content-Type", "application/x-protobuf");
		int len = bytes.length + 2;
		byte[] temp = new byte[len];
		byte[] sArr = shortToByteArray((short) 1);
		System.arraycopy(sArr, 0, temp, 0, 2);
		System.arraycopy(bytes, 0, temp, 2, len - 2);
		req.setData(temp);
		Response resp = Sender.create(req).send();

		Message.Builder builder = UserProto.User.newBuilder();
		try {
			builder.mergeFrom(resp.getStream(), ExtensionRegistry.newInstance());
		} catch (IOException e) {
			log.error(e);
		}
		Message res = builder.build();
		System.out.println(res);
	}

	private static byte[] shortToByteArray(short s) {
		byte[] shortBuf = new byte[2];
		for (int i = 0; i < 2; i++) {
			int offset = (shortBuf.length - 1 - i) * 8;
			shortBuf[i] = (byte) ((s >>> offset) & 0xff);
		}
		return shortBuf;
	}

	public static void main(String[] args) throws IOException {

		Codec<UserJProtoBufProtoClass> codec = ProtobufProxy.create(UserJProtoBufProtoClass.class);
		UserJProtoBufProtoClass udbp = new UserJProtoBufProtoClass();
		udbp.id = System.currentTimeMillis();
		udbp.name = "lisi";
		byte[] bytes = codec.encode(udbp);
		String url = "http://127.0.0.1:8080/nutz_buff/jprotoa";
		Request req = Request.create(url, METHOD.POST);
		req.getHeader().set("Content-Type", "application/x-protobuf");
		req.setData(bytes);
		Response resp = Sender.create(req).send();
		UserJProtoBufProtoClass resudbp = codec.decode(Streams.readBytes(resp.getStream()));
		System.out.println(resudbp.name);
		System.out.println(resudbp.id);
	}

当访问jproto 的时候报

2016-08-11 11:07:33,456 [WARN][org.nutz.mvc.impl.processor.FailProcessor] - Error@/jproto :
java.lang.RuntimeException: java.io.FileNotFoundException: messageType [2224] MessgeClass Not find
	at org.nutz.lang.Lang.wrapThrow(Lang.java:148)
	at com.rekoe.protobuf.mvc.adaptor.JProtobufAdaptor.getReferObject(JProtobufAdaptor.java:76)
	at org.nutz.mvc.adaptor.AbstractAdaptor.adapt(AbstractAdaptor.java:216)
	at com.rekoe.protobuf.mvc.adaptor.JProtobufAdaptor.adapt(JProtobufAdaptor.java:40)
	at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:28)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:40)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:113)
	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:40)
	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:183)
	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:220)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
	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:956)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:436)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.FileNotFoundException: messageType [2224] MessgeClass Not find
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
	at org.nutz.lang.born.ConstructorBorning.born(ConstructorBorning.java:17)
	at org.nutz.lang.born.BornContext.doBorn(BornContext.java:60)
	at org.nutz.lang.Mirror.born(Mirror.java:967)
	at org.nutz.lang.Lang.makeThrow(Lang.java:116)
	at com.rekoe.protobuf.mvc.adaptor.JProtobufAdaptor.getReferObject(JProtobufAdaptor.java:67)
	... 32 more

然后我用插件的方法 即jprotoa
时报

java.lang.IllegalArgumentException: Method miss match: expect public com.rekoe.protobuf.pojo.UserJProtoBufProtoClass com.rekoe.protobuf.mobule.ProtobufMobule.jprotoa(com.rekoe.protobuf.pojo.UserJProtoBufProtoClass) but public com.google.protobuf.Message com.rekoe.protobuf.mobule.ProtobufMobule.jproto(com.google.protobuf.Message,short). using Ioc? set singleton=false, pls
	at com.rekoe.protobuf.mvc.adaptor.JProtobufAdaptor.adapt(JProtobufAdaptor.java:38)
	at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:28)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:40)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:113)
	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:40)
	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:183)
	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:220)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
	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:956)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:436)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:745)

然后我有点方

这个是ioc js里面要配置为非单例

java.lang.IllegalArgumentException: Method miss match: expect public com.rekoe.protobuf.pojo.UserJProtoBufProtoClass com.rekoe.protobuf.mobule.ProtobufMobule.jprotoa(com.rekoe.protobuf.pojo.UserJProtoBufProtoClass) but public com.google.protobuf.Message com.rekoe.protobuf.mobule.ProtobufMobule.jproto(com.google.protobuf.Message,short). using Ioc? set singleton=false, pls

非单例咋配。。。而且非单例会有啥影响 因为这只是个demo

var ioc = {
	protobufAdaptor : {
		type : "org.nutz.plugins.protobuf.mvc.adaptor.ProtobufAdaptor",
		singleton: false
	},
	jprotobufAdaptor : {
		type : "org.nutz.plugins.protobuf.mvc.adaptor.JProtobufAdaptor",
		singleton: false
	}
};

错误信息

Caused by: java.io.FileNotFoundException: messageType [2192] MessgeClass Not find
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
	at org.nutz.lang.born.ConstructorBorning.born(ConstructorBorning.java:17)
	at org.nutz.lang.born.BornContext.doBorn(BornContext.java:60)
	at org.nutz.lang.Mirror.born(Mirror.java:967)
	at org.nutz.lang.Lang.makeThrow(Lang.java:116)
	at com.rekoe.protobuf.mvc.adaptor.JProtobufAdaptor.getReferObject(JProtobufAdaptor.java:67)
	... 32 more

ioc信息

var ioc = {
	protobufAdaptor : {
		type : "com.rekoe.protobuf.mvc.adaptor.ProtobufAdaptor",
		args : [ {
			refer : "protoBufMessageFactory"
		} ]
	},
	jprotobufAdaptor : {
		type : "com.rekoe.protobuf.mvc.adaptor.JProtobufAdaptor",
		args : [ {
			refer : "protoBufMessageFactory"
		} ]
	},
	protoBufMessageFactory : {
		type : "com.rekoe.protobuf.mvc.adaptor.ProtoBufMessageFactory",
		events : {
			create : "init"
		}
	}
};

@qq_3c29d04b 这不是完整报错信息吧? 贴全啊

不好意思 这是完整报错信息
已经在ioc里改成了非单例

2016-08-11 11:58:19,744 [DEBUG][org.nutz.mvc.impl.UrlMappingImpl] - Found mapping for [POST] path=/jprotoa : ProtobufMobule.jprotoa(...)
2016-08-11 11:58:19,746 [DEBUG][org.nutz.ioc.impl.NutIoc] - Get 'protobufMobule'<class com.rekoe.protobuf.mobule.ProtobufMobule>
2016-08-11 11:58:19,746 [DEBUG][org.nutz.ioc.impl.NutIoc] - 	 >> Load definition
2016-08-11 11:58:19,746 [DEBUG][org.nutz.ioc.loader.combo.ComboIocLoader] - Found IocObject(protobufMobule) in IocLoader(AnnotationIocLoader@853142502)
2016-08-11 11:58:19,746 [DEBUG][org.nutz.ioc.impl.NutIoc] - 	 >> Make...'protobufMobule'<class com.rekoe.protobuf.mobule.ProtobufMobule>
2016-08-11 11:58:19,747 [DEBUG][org.nutz.ioc.aop.impl.DefaultMirrorFactory] - class com.rekoe.protobuf.mobule.ProtobufMobule without AOP
2016-08-11 11:58:19,747 [DEBUG][org.nutz.ioc.impl.ScopeContext] - Save object 'protobufMobule' to [app] 
2016-08-11 11:58:19,748 [DEBUG][com.rekoe.protobuf.mvc.adaptor.JProtobufAdaptor] - null
2016-08-11 11:58:19,749 [WARN][org.nutz.mvc.impl.processor.FailProcessor] - Error@/jprotoa :
java.lang.RuntimeException: java.io.FileNotFoundException: messageType [2242] MessgeClass Not find
	at org.nutz.lang.Lang.wrapThrow(Lang.java:148)
	at com.rekoe.protobuf.mvc.adaptor.JProtobufAdaptor.getReferObject(JProtobufAdaptor.java:76)
	at org.nutz.mvc.adaptor.AbstractAdaptor.adapt(AbstractAdaptor.java:216)
	at com.rekoe.protobuf.mvc.adaptor.JProtobufAdaptor.adapt(JProtobufAdaptor.java:40)
	at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:28)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:40)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:113)
	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:40)
	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:183)
	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:220)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
	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:956)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:436)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.FileNotFoundException: messageType [2242] MessgeClass Not find
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
	at org.nutz.lang.born.ConstructorBorning.born(ConstructorBorning.java:17)
	at org.nutz.lang.born.BornContext.doBorn(BornContext.java:60)
	at org.nutz.lang.Mirror.born(Mirror.java:967)
	at org.nutz.lang.Lang.makeThrow(Lang.java:116)
	at com.rekoe.protobuf.mvc.adaptor.JProtobufAdaptor.getReferObject(JProtobufAdaptor.java:67)
	... 32 more

at com.rekoe.protobuf.mvc.adaptor.JProtobufAdaptor.getReferObject(JProtobufAdaptor.java:67)

用的不是插件里面的JProtobufAdaptor, 那是@rekoe 之前在自己项目中写的版本, 没有考虑 @Attr("messageType") short messageType 这种.

把这个参数去掉试试.

此贴因为用的不是官方文档 从现在开始计数

首先Main函数里配置了

@SetupBy(value = DataSource.class)
@IocBy(type = ComboIocProvider.class, args = { "*js", "ioc/", "*anno", "com.egfbank.datacentor", "*tx",
		"*org.nutz.integration.quartz.QuartzIocLoader" })
@Views({ ProtoViewMaker.class })
@Modules(scanPackage = true)
public class MainModule {

}

然后创建了一个SearchModule

test亲测有效 后注销

	@At
	@Ok("ioc:jproto")
	@AdaptBy(type = JProtobufAdaptor.class, args = { "ioc:jprotobufAdaptor" })
	public SingleModel ValidatorCardInfo(SingleModel message) {
		return message;
	}
//	@At
//	@Ok("json:full")
//	public String test(){
//		return "123";
//	}

模板类

public class SingleModel {

	@Protobuf(fieldType = FieldType.STRING, order = 1, required = true)
	private String orderCode;
	
	@Protobuf(fieldType = FieldType.STRING, order = 2, required = true)
	private String msg;

ioc

var ioc = {
	protobufAdaptor : {
		type : "org.nutz.plugins.protobuf.mvc.adaptor.ProtobufAdaptor",
		singleton : false
	},
	jprotobufAdaptor : {
		type : "org.nutz.plugins.protobuf.mvc.adaptor.JProtobufAdaptor",
		singleton : false
	}
};

启动时的全部日志

13:53:27,921  INFO NutFilter:81 - NutFilter[nutz] starting ...
13:53:28,353  INFO NutLoading:55 - Nutz Version : 1.r.57.r3 
13:53:28,354  INFO NutLoading:56 - Nutz.Mvc[nutz] is initializing ...
13:53:28,653  INFO AnnotationIocLoader:50 - Found 3 classes in 1 base-packages!
beans = ["testTask", "searchModule", "search1Module"]
13:53:28,662  INFO NutIoc:98 - NutIoc init begin ...
13:53:28,670  INFO NutIoc:115 - ... NutIoc init complete
13:53:28,675  INFO NutLoading:158 - Build URL mapping by org.nutz.mvc.impl.UrlMappingImpl ...
13:53:28,705  INFO NutActionChainMaker:72 - Optional processor class not found, disabled : org.nutz.integration.shiro.NutShiroProcessor
13:53:28,728  INFO NutActionChainMaker:72 - Optional processor class not found, disabled : org.nutz.plugins.validation.ValidationProcessor
13:53:28,733 ERROR NutLoading:124 - Error happend during start serivce!
org.nutz.ioc.IocException: [jproto] # For object [jproto] - type:[interface org.nutz.mvc.View]
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:218)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:239)
	at org.nutz.mvc.view.DefaultViewMaker.make(DefaultViewMaker.java:65)
	at org.nutz.mvc.view.ViewZone.makeView(ViewZone.java:86)
	at org.nutz.mvc.impl.processor.ViewProcessor.evalView(ViewProcessor.java:89)
	at org.nutz.mvc.impl.processor.ViewProcessor.init(ViewProcessor.java:31)
	at org.nutz.mvc.impl.NutActionChainMaker.eval(NutActionChainMaker.java:38)
	at org.nutz.mvc.impl.UrlMappingImpl.add(UrlMappingImpl.java:47)
	at org.nutz.mvc.impl.NutLoading.evalUrlMapping(NutLoading.java:203)
	at org.nutz.mvc.impl.NutLoading.load(NutLoading.java:107)
	at org.nutz.mvc.ActionHandler.<init>(ActionHandler.java:19)
	at org.nutz.mvc.NutFilter._init(NutFilter.java:87)
	at org.nutz.mvc.NutFilter.init(NutFilter.java:65)
	at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:279)
	at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:260)
	at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:105)
	at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4908)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5602)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1572)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1562)
	at java.util.concurrent.FutureTask.run(FutureTask.java:262)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at java.lang.Thread.run(Thread.java:745)
Caused by: org.nutz.ioc.ObjectLoadException: Object 'jproto' without define!
	at org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:174)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:180)
	... 24 more
13:53:28,740 ERROR NutLoading:126 - try to depose ioc
13:53:28,744  INFO NutIoc:255 - org.nutz.ioc.impl.NutIoc@1066484747 is closing. startup date [16-08-11 13:53:28.663]
13:53:28,744  INFO NutIoc:262 - org.nutz.ioc.impl.NutIoc@1066484747 is deposed. startup date [16-08-11 13:53:28.663]
八月 11, 2016 1:53:28 下午 org.apache.catalina.core.StandardContext filterStart
严重: Exception starting filter nutz
org.nutz.mvc.LoadingException: org.nutz.ioc.IocException: [jproto] # For object [jproto] - type:[interface org.nutz.mvc.View]
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
	at org.nutz.lang.born.ConstructorBorning.born(ConstructorBorning.java:17)
	at org.nutz.lang.born.BornContext.doBorn(BornContext.java:60)
	at org.nutz.lang.Mirror.born(Mirror.java:990)
	at org.nutz.lang.Lang.wrapThrow(Lang.java:169)
	at org.nutz.mvc.impl.NutLoading.load(NutLoading.java:134)
	at org.nutz.mvc.ActionHandler.<init>(ActionHandler.java:19)
	at org.nutz.mvc.NutFilter._init(NutFilter.java:87)
	at org.nutz.mvc.NutFilter.init(NutFilter.java:65)
	at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:279)
	at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:260)
	at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:105)
	at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4908)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5602)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1572)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1562)
	at java.util.concurrent.FutureTask.run(FutureTask.java:262)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at java.lang.Thread.run(Thread.java:745)
Caused by: org.nutz.ioc.IocException: [jproto] # For object [jproto] - type:[interface org.nutz.mvc.View]
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:218)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:239)
	at org.nutz.mvc.view.DefaultViewMaker.make(DefaultViewMaker.java:65)
	at org.nutz.mvc.view.ViewZone.makeView(ViewZone.java:86)
	at org.nutz.mvc.impl.processor.ViewProcessor.evalView(ViewProcessor.java:89)
	at org.nutz.mvc.impl.processor.ViewProcessor.init(ViewProcessor.java:31)
	at org.nutz.mvc.impl.NutActionChainMaker.eval(NutActionChainMaker.java:38)
	at org.nutz.mvc.impl.UrlMappingImpl.add(UrlMappingImpl.java:47)
	at org.nutz.mvc.impl.NutLoading.evalUrlMapping(NutLoading.java:203)
	at org.nutz.mvc.impl.NutLoading.load(NutLoading.java:107)
	... 15 more
Caused by: org.nutz.ioc.ObjectLoadException: Object 'jproto' without define!
	at org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:174)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:180)
	... 24 more

八月 11, 2016 1:53:28 下午 org.apache.catalina.core.StandardContext startInternal
严重: One or more Filters failed to start. Full details will be found in the appropriate container log file
八月 11, 2016 1:53:28 下午 org.apache.catalina.core.StandardContext startInternal
严重: Context [/cpospdc] startup failed due to previous errors
八月 11, 2016 1:53:28 下午 org.apache.coyote.AbstractProtocol start
信息: Starting ProtocolHandler ["http-bio-8080"]
八月 11, 2016 1:53:28 下午 org.apache.coyote.AbstractProtocol start
信息: Starting ProtocolHandler ["ajp-bio-8009"]
八月 11, 2016 1:53:28 下午 org.apache.catalina.startup.Catalina start
信息: Server startup in 2607 ms

求大大给看看

@qq_3c29d04b 方法声明贴出来

来自炫酷的 NutzCN

你js里配置的是 jprotobufAdaptor
而你调用的是 jproto

视图没有加入到ioc中

扫描下这个路径下的类

org.nutz.plugins.protobuf.mvc.view

@Rekoe 给一下demo配置呗

来自炫酷的 NutzCN

我的意思是

@IocBean(name = "proto")
public class ProtoView implements View 

扫描整个路径下的这连个类

"*anno", "com.egfbank.datacentor","org.nutz.plugins.protobuf.mvc.view"

或者直接

@Ok("jproto")
@Ok("proto")

结贴
在各位的帮助下
原因是ioc需要扫描view目录

最后修改为

@SetupBy(value = DataSource.class)
@IocBy(type = ComboIocProvider.class, args = { "*js", "ioc/", "*anno", "com.egfbank.datacentor","org.nutz.plugins.protobuf.mvc.view", "*tx",
		"*org.nutz.integration.quartz.QuartzIocLoader" })
@Views({ ProtoViewMaker.class })
@Modules(scanPackage = true)
public class MainModule {

}

org.nutz.plugins.protobuf.mvc.view 增加到IocBy里
over

随便提一句

"*org.nutz.integration.quartz.QuartzIocLoader"
// 在高版本的nutz中,可以简写为
"*quartz"

不好意思又来麻烦大家
调用失败

14:34:50,341  WARN FailProcessor:28 - Error@/search/ValidatorCardInfo :
java.lang.IllegalArgumentException: Not Support Adaptor,You Must Have A Message Type Class 
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
	at org.nutz.lang.born.ConstructorBorning.born(ConstructorBorning.java:17)
	at org.nutz.lang.born.BornContext.doBorn(BornContext.java:60)
	at org.nutz.lang.Mirror.born(Mirror.java:990)
	at org.nutz.lang.Lang.makeThrow(Lang.java:121)
	at org.nutz.plugins.protobuf.mvc.adaptor.JProtobufAdaptor.getReferObject(JProtobufAdaptor.java:60)
	at org.nutz.mvc.adaptor.AbstractAdaptor.adapt(AbstractAdaptor.java:226)
	at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:28)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:58)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:123)
	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:198)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123)
	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:220)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
	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:956)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:436)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:745)

你的入口函数没有属性

你传的数据会通过这个类来接收

@At
	@Ok("jproto")
	@AdaptBy(type = JProtobufAdaptor.class, args = { "ioc:jprotobufAdaptor" })
	public SingleModel ValidatorCardInfo(SingleModel message) {
		return message;
	}

SingleModel类

public class SingleModel {

	@Protobuf(fieldType = FieldType.STRING, order = 1, required = true)
	private String orderCode;
	
	@Protobuf(fieldType = FieldType.STRING, order = 2, required = true)
	private String msg;

看起来应该跟demo不差啊!

附带请求
完全照抄

	public static void testJProtobuf() throws IOException {
		Codec<SingleModel> codec = ProtobufProxy.create(SingleModel.class);
		SingleModel udbp = new SingleModel();
		udbp.setMsg("123");
		udbp.setOrderCode("333");
		byte[] bytes = codec.encode(udbp);
		String url = "http://127.0.0.1:8080/cpospdc/search/ValidatorCardInfo";
		Request req = Request.create(url, METHOD.POST);
		req.getHeader().set("Content-Type", "application/x-protobuf");
		req.setData(bytes);
		Response resp = Sender.create(req).send();
		SingleModel resudbp = codec.decode(Streams.readBytes(resp.getStream()));
		System.out.println(resudbp.getMsg());
		System.out.println(resudbp.getOrderCode());
	}

看了看代码, 属性必须是public才行

public class SingleModel {

	@Protobuf(fieldType = FieldType.STRING, order = 1, required = true)
	public String orderCode;
	
	@Protobuf(fieldType = FieldType.STRING, order = 2, required = true)
	public String msg;

顺便更新了README文档

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