分布式网上商城项目-dubbo搭建与初次使用错误

Posted floatthy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了分布式网上商城项目-dubbo搭建与初次使用错误相关的知识,希望对你有一定的参考价值。

 

1、Spring-service启动失败

 

 1 严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
 2 
 3 org.springframework.beans.factory.BeanCreationException: Error creating bean with name \'testServiceImpl\': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [cn.thyoline.taotao.mapper.TestMapper] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.annotation.Resource(name="", shareable=true, description="", authenticationType=CONTAINER, type=java.lang.Object.class, mappedName="")}
 4 
 5          at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:311)
 6 
 7          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
 8 
 9          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
10 
11          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
12 
13          at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
14 
15          at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
16 
17          at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
18 
19          at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
20 
21          at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
22 
23          at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
24 
25          at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
26 
27          at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:446)
28 
29          at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:328)
30 
31          at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
32 
33          at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939)
34 
35          at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434)
36 
37          at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
38 
39          at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
40 
41          at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
42 
43          at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
44 
45          at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1135)
46 
47          at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
48 
49          at java.base/java.lang.Thread.run(Thread.java:844)
50 
51 Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [cn.thyoline.taotao.mapper.TestMapper] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.annotation.Resource(name="", shareable=true, description="", authenticationType=CONTAINER, type=java.lang.Object.class, mappedName="")}
52 
53          at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1373)
54 
55          at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1119)
56 
57          at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014)
58 
59          at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:508)
60 
61          at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:486)
62 
63          at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:615)
64 
65          at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:169)
66 
67          at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
68 
69          at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:308)
70 
71          ... 22 more

 可知找不到bean of type [cn.thyoline.taotao.mapper.TestMapper] 检查之后发现mapper的映射文件和mapper不匹配修改之后

 

运行之后还是有错误:

可以看出是无法自动装入字段:private cn.thyonline.taotao.mapper.TestMapper,是mapper文件的命名空间出错,检查之后发现已经修改过,但是在target包中的文件没有修改。于是,重新install

 

再次运行service层的Tomcat,运行成功

 

2、Spring-web启动失败

 

 1 2018-06-01 14:56:55,300 [localhost-startStop-1-SendThread(192.168.25.128:2181)] [org.apache.zookeeper.ClientCnxn]-[WARN] Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect
 2 
 3 java.net.ConnectException: Connection refused: no further information
 4 
 5          at java.base/sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
 6 
 7          at java.base/sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717)
 8 
 9          at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:361)
10 
11          at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1141)

意思就是,未能找到执行目标,检查之后发现zookeeper未打开; 

打开zookeeper:

 1 [root@localhost bin]# ./zkServer.sh start
 2 
 3 JMX enabled by default
 4 
 5 Using config: /root/zookeeper-3.4.6/bin/../conf/zoo.cfg
 6 
 7 Starting zookeeper ... STARTED
 8 
 9 [root@localhost bin]# ./zkServer.sh status
10 
11 JMX enabled by default
12 
13 Using config: /root/zookeeper-3.4.6/bin/../conf/zoo.cfg
14 
15 Mode: standalone(证明成功打开)

 

运行成功 

 

 

3、在加载静态页面之后再启动,启动不了

 

在web层发现是没有接收到testService的目标,检查zookeeper之后,发现运行正常,应该是service层没有注册,于是检查发现

 1 信息: Initializing ProtocolHandler ["http-bio-8080"]
 2 
 3 6月 01, 2018 4:47:58 下午 org.apache.catalina.core.StandardService startInternal
 4 
 5 信息: Starting service Tomcat
 6 
 7 6月 01, 2018 4:47:58 下午 org.apache.catalina.core.StandardEngine startInternal
 8 
 9 信息: Starting Servlet Engine: Apache Tomcat/7.0.47
10 
11 6月 01, 2018 4:48:00 下午 org.apache.catalina.core.ApplicationContext log
12 
13 信息: No Spring WebApplicationInitializer types detected on classpath
14 
15 6月 01, 2018 4:48:00 下午 org.apache.catalina.core.ApplicationContext log
16 
17 信息: Initializing Spring root WebApplicationContext
18 
19 log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
20 
21 log4j:WARN Please initialize the log4j system properly.
22 
23 log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

Tomcat卡在这动不了了 

网上搜索找到原因了~

 

1,多数情况下是连接数据库时出现问题,

 

2,如果使用mybatis 请查看 xml映射文件是否和对应的java 的dao文件名字相同,或者<mapper namespace="com.hlzt.wx.dao.TextReplyDao" >  <resultMap id="BaseResultMap" type="TextReply" > 的命名空间 com.hlzt.wx.dao.TextReplyDao是否对应,BaseResultMap type="TextReply" 的 TextReply是否定义等等。

 

3,检查mybatis 映射文件xml,中标签是否完全闭合,不能只有开始标签而没有闭合标签,要符合规范,不然web初始化时会一直卡在那

 

检查映射文件,发现

<mapper namespace="com.hlzt.wx.dao.TextReplyDao" >

parameterType="TbContentCategoryExample"

在逆向工程的时候是对应的当时的文件夹,没有对应,于是在spring的配置文件里面配置别名并且修改映射文件之后成功启动

以上是关于分布式网上商城项目-dubbo搭建与初次使用错误的主要内容,如果未能解决你的问题,请参考以下文章

分布式事务tcc-transaction分布式TCC型事务框架搭建与实战案例(基于Dubbo/Dubbox)

Spring+Dubbo搭建一个简单的分布式

电商项目maven框架搭建引入dubbo配置文件报错

超详细,新手都能看懂 !大牛带你使用SpringBoot+Dubbo 搭建一个简单的分布式服务,还附带坦克大战项目,速看!

Dubbo入门实例

dubbo在项目有啥作用