重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
本篇内容介绍了“zookeeper商城项目举例分析”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
成都创新互联-专业网站定制、快速模板网站建设、高性价比李沧网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式李沧网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖李沧地区。费用合理售后完善,十余年实体公司更值得信赖。
1.项目初始化启动时,报错
[INFO] Scanning for projects... [ERROR] [ERROR] Some problems were encountered while processing the POMs: [FATAL] Non-resolvable parent POM for com.zfsoft:shoping-web:0.0.1-SNAPSHOT: Could not find artifact com.zfsoft:shoping-parent:pom:0.0.1-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 3, column 11 @ [ERROR] The build could not read 1 project -> [Help 1] [ERROR] [ERROR] The project com.zfsoft:shoping-web:0.0.1-SNAPSHOT (E:\eclipseWorkspace\shoping-web\pom.xml) has 1 error [ERROR] Non-resolvable parent POM for com.zfsoft:shoping-web:0.0.1-SNAPSHOT: Could not find artifact com.zfsoft:shoping-parent:pom:0.0.1-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 3, column 11 -> [Help 2] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException [ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException
解决办法:
Non-resolvable parent POM for com.zfsoft:shoping-web:0.0.1-SNAPSHOT: Could not find artifact com.zfsoft:shoping-parent:pom:0.0.1-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 3, column 11 -> [Help 2]
本地仓库中没有shoping-parent,右键parent---maven install
2.运行继续报错
[INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building shoping-web 0.0.1-SNAPSHOT [INFO] ------------------------------------------------------------------------ [WARNING] The POM for com.zfsoft:shoping-interface:jar:0.0.1-SNAPSHOT is missing, no dependency information available [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 0.524 s [INFO] Finished at: 2019-07-08T23:45:55+08:00 [INFO] Final Memory: 8M/154M [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal on project shoping-web: Could not resolve dependencies for project com.zfsoft:shoping-web:war:0.0.1-SNAPSHOT: Could not find artifact com.zfsoft:shoping-interface:jar:0.0.1-SNAPSHOT -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
解决:多添加了interface的依赖
3.使用maven tomcat7插件运行报错:The ServletContentInitializer [org.springframework.web.SpringServletContainerInitializer] could not be created
[INFO] --- tomcat7-maven-plugin:2.2:run (default-cli) @ taotao-manager-web --- [INFO] Running war on http://localhost:8080/ [INFO] Creating Tomcat server configuration at F:\eclipse-workspace-7-24\taotao-manager\taotao-manager-web\target\tomcat [INFO] create webapp with contextPath: 八月 11, 2017 4:14:41 下午 org.apache.coyote.AbstractProtocol init 信息: Initializing ProtocolHandler ["http-bio-8080"] 八月 11, 2017 4:14:41 下午 org.apache.catalina.core.StandardService startInternal 信息: Starting service Tomcat 八月 11, 2017 4:14:41 下午 org.apache.catalina.core.StandardEngine startInternal 信息: Starting Servlet Engine: Apache Tomcat/7.0.47 八月 11, 2017 4:14:42 下午 org.apache.catalina.startup.ContextConfig getServletContainerInitializer 严重: The ServletContentInitializer [org.springframework.web.SpringServletContainerInitializer] could not be created java.lang.ClassNotFoundException: org.springframework.web.SpringServletContainerInitializer at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1702) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1547) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Unknown Source) at org.apache.catalina.startup.ContextConfig.getServletContainerInitializer(ContextConfig.java:1668) at org.apache.catalina.startup.ContextConfig.getServletContainerInitializers(ContextConfig.java:1652) at org.apache.catalina.startup.ContextConfig.processServletContainerInitializers(ContextConfig.java:1562)
解决:
jar包不完整,删除仓库中的jar包,然后重启项目,右键项目---maven---maven update
4.因为使用soa架构,在service层的web.xml配置完初始化spring容器后,在web层还需要再配一个吗?不用。
一般我们在父容器applicationcontext这种配置扫描包dao、service,子容器中配置扫描controller/action
即便配置只扫描到shoping,父容器中有controller,但是依旧没有意义;子容器中也就会有dao、service那他就不会再去父容器中找了,但是事务是在父容器中配的,子容器中使用的service是没有事务增强的
父子容器他们功能完全相同,但是DispatcherServlet毕竟是一个表现层框架,使用父容器还可以和别的框架整合,扩展性更好(比如父容器中再使用Struts2)
4.RestFul
webservice一遍(使用cxf可以发布restful服务),本质是http请求(get或者post)。springmvc从路径中取值:@pathVariable
5.Dubbo只能是java和java之间通信,和其他通信使用其他两种方式:webservice(基于soap)、resful形式(http+json)
什么是Dubbo:服务治理中间件
Cluster:集群节点
传统的单一系统可以布置1-10个节点。tomcat集群,session共享,之后配置session广播。1-10个,再多性能下降
Dubbo架构
注册中心:
zookeeper(集群管理工具),可以管理hodoop集群等等。但是dubbo中zookeeper是用来做注册中心的,不用来管理集群。
当然也可以使用redis作为注册中心
使用步骤(Linux版)
解压缩---》目录下新建data文件夹
切换到conf目录,将zoo_sample.cfg改名为zoo.cfg
编辑zzoo.cfg,将dataDir改为刚才新建的data目录
回到bin目录启动zookeeper
查看是否启动成功
7,问题:spring明明定义的是4.2但是里面依赖进来了2.6的jar包
解决:
右键exclusion,然后回到pom文件处查看
已经被排除,保存pom文件即可
继续排除冲突jar包,方法同上
dubbo的配置文件
在service模块中
在web模块中
8.问题:406错误
如果有时候出现406错误,可能是没有吧jackson包加进来
9.问题:测试dubbo的时候,控制台卡主,看不到错误信息,添加log4j.properties后,发现报错
Opening socket connection to server 10.70.42.99/10.70.42.99:2181. Will not attempt to authenticate using SASL (无法定位登录配置)
原因:服务器端口开放2181或者关闭防火墙,同时阿里云服务器开放2181端口
10.dubbo配置完成后,启动项目
11.启动项目后输入web层的mapping:http://localhost:8081/item/679532
报错
[DUBBO] Got unchecked and undeclared exception which called by 192.168.1.109. service: com.shoping.service.ItemService, method: findById, exception: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.shoping.mapper.TbItemMapper.selectByPrimaryKey, dubbo version: 2.5.3, current host: 127.0.0.1 org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.shoping.mapper.TbItemMapper.selectByPrimaryKey
找不到对应的实现,但是这个是通过mybatis逆向工程生成的
也就是xml文件就是实现类了,去编译后的目录查看
只有dao模块接口类的class文件,并没有xml文件。mapping映射文件未发布的问题。
配置的作用:吧src/main/java目录下的xml文件也配置到编译后的目录下
重启manage模块,并查看编译后的目录
重新输入地址,又报错
后台报错内容
[DUBBO] Fail to encode response: Response [id=6, version=2.0.0, status=20, event=false, error=null, result=RpcResult [result=com.shoping.pojo.TbItem@7d82ecd5, exception=null]], send bad_response info instead, cause: Serialized class com.shoping.pojo.TbItem must implement java.io.Serializable, dubbo version: 2.5.3, current host: 127.0.0.1 java.lang.IllegalStateException: Serialized class com.shoping.pojo.TbItem must implement java.io.Serializable at com.alibaba.com.caucho.hessian.io.SerializerFactory.getDefaultSerializer(SerializerFactory.java:261) at com.alibaba.com.caucho.hessian.io.SerializerFactory.getSerializer(SerializerFactory.java:233) at com.alibaba.com.caucho.hessian.io.Hessian2Output.writeObject(Hessian2Output.java:406) at com.alibaba.dubbo.common.serialize.support.hessian.Hessian2ObjectOutput.writeObject(Hessian2ObjectOutput.java:92) at com.alibaba.dubbo.rpc.protocol.dubbo.DubboCodec.encodeResponseData(DubboCodec.java:200) at com.alibaba.dubbo.remoting.exchange.codec.ExchangeCodec.encodeResponse(ExchangeCodec.java:276) at com.alibaba.dubbo.remoting.exchange.codec.ExchangeCodec.encode(ExchangeCodec.java:77) at com.alibaba.dubbo.rpc.protocol.dubbo.DubboCountCodec.encode(DubboCountCodec.java:39) at com.alibaba.dubbo.remoting.transport.netty.NettyCodecAdapter$InternalEncoder.encode(NettyCodecAdapter.java:81) at org.jboss.netty.handler.codec.oneone.OneToOneEncoder.doEncode(OneToOneEncoder.java:66) at org.jboss.netty.handler.codec.oneone.OneToOneEncoder.handleDownstream(OneToOneEncoder.java:59) at org.jboss.netty.channel.DefaultChannelPipeline.sendDownstream(DefaultChannelPipeline.java:591) at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendDownstream(DefaultChannelPipeline.java:784) at org.jboss.netty.channel.SimpleChannelHandler.writeRequested(SimpleChannelHandler.java:292) at com.alibaba.dubbo.remoting.transport.netty.NettyHandler.writeRequested(NettyHandler.java:99) at org.jboss.netty.channel.SimpleChannelHandler.handleDownstream(SimpleChannelHandler.java:254) at org.jboss.netty.channel.DefaultChannelPipeline.sendDownstream(DefaultChannelPipeline.java:591) at org.jboss.netty.channel.DefaultChannelPipeline.sendDownstream(DefaultChannelPipeline.java:582) at org.jboss.netty.channel.Channels.write(Channels.java:704) at org.jboss.netty.channel.Channels.write(Channels.java:671) at org.jboss.netty.channel.AbstractChannel.write(AbstractChannel.java:248) at com.alibaba.dubbo.remoting.transport.netty.NettyChannel.send(NettyChannel.java:98) at com.alibaba.dubbo.remoting.transport.AbstractPeer.send(AbstractPeer.java:51) at com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.received(HeaderExchangeHandler.java:171) at com.alibaba.dubbo.remoting.transport.DecodeHandler.received(DecodeHandler.java:52) at com.alibaba.dubbo.remoting.transport.dispatcher.ChannelEventRunnable.run(ChannelEventRunnable.java:82) 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:744)
实体对象没有序列化,加上序列化接口即可
10.dubbo监控中心
前面已经安装了zookeeper注册中心,生产者,消费者,还有个监控中心
把dubbo-admin.war放到tomcat的webapps下面
启动tomcat,输入网址:http://47.97.125.139:8080/dubbo-admin
点进去,可以看到生产者服务的ip和端口号
切换到消费者
“zookeeper商城项目举例分析”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注创新互联网站,小编将为大家输出更多高质量的实用文章!