微服务搭建问题

错误汇总:
1:
异常:
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Wed Dec 14 16:35:25 CST 2016
There was an unexpected error (type=Not Found, status=404).
No message available
原因:【Application启动类放的位置不对】要将Application放在最外层,也就是要包含所有子包。
 
2:
导入的mvn项目报错:
Description    Resource    Path    Location    Type Failure to transfer org.apache.commons:commons-compress:jar:
原因:
ide编辑器中maven设置有问题
解决:
 
3:页面输入URL报错: This application has no explicit mapping for /error, so you are seeing this as a fallback
原因:
    controller类使用了@Controller造成的。
    @Controller会将返回的信息当作URL处理。
    @RestController直接将信息当作Content处理。
解决:
    将@Controller改为@RestController即可解决
 
4:
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jedisConnectionFactory' defined in class path resource [spring-redis.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.redis.connection.jedis.JedisConnectionFactory]: No default constructor found; nested exception is java.lang.NoClassDefFoundError: redis/clients/util/Pool
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1270)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1164)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:538)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498)
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:846)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:863)
    at org.springframework.context.support.AbstractApplicationContext.__refresh(AbstractApplicationContext.java:546)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:400)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:291)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:103)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    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:745)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.redis.connection.jedis.JedisConnectionFactory]: No default constructor found; nested exception is java.lang.NoClassDefFoundError: redis/clients/util/Pool
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:83)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1262)
    ... 23 more
Caused by: java.lang.NoClassDefFoundError: redis/clients/util/Pool
    at java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671)
    at java.lang.Class.getConstructor0(Class.java:3075)
    at java.lang.Class.getDeclaredConstructor(Class.java:2178)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:78)
    ... 24 more
Caused by: java.lang.ClassNotFoundException: redis.clients.util.Pool
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1702)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1547)
    ... 29 more
问题原因:pom.xml中引入的两个redis相关jar不兼容.
<!--Spring整合redis包 -->
<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-redis</artifactId>
    <version>2.1.3.RELEASE</version>
</dependency>
<dependency>
    <groupId>redis.clients</groupId>
    <artifactId>jedis</artifactId>
    <version>3.0.0</version>
</dependency>
解决办法:降低redis.clients的版本:
<!--Spring整合redis包 -->
<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-redis</artifactId>
    <version>2.1.3.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/redis.clients/jedis -->
<!-- https://mvnrepository.com/artifact/redis.clients/jedis -->
<dependency>
    <groupId>redis.clients</groupId>
    <artifactId>jedis</artifactId>
    <version>2.9.1</version>
</dependency>
zuul问题汇总
1:
异常:应用正常启动,但是路由无法进行,并且没有报错
原因:路径前缀被清除导致的
解决:添加
zuul.routes.tp-cust.stripPrefix=false
2:
异常:
原因:超时时间未设置
解决:
zuul.host.readTimeoutMillis=30000
zuul.host.connectTimeoutMillis=30000
zuul.host.socketTimeout-Millis=30000
 
Feign错误
1:
问题
com.netflix.client.ClientException: Load balancer does not have available server for client:XXXX
原因:未开启使用eureka
解决:
添加ribbon.eureka.enable=true
 
2:
超时异常
解决:
ribbon.ReadTimeout=60000
ribbon.ConnectTimeout=60000
3:
请求异常
ervlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is feign.codec.DecodeException: JSON parse error: Can not construct instance of com.kanshu.dao.model.User: no suitable constructor found, can not deserialize from Object value (missing default constructor or creator, or perhaps need to add/enable type information?); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of com.kanshu.dao.model.User: no suitable constructor found, can not deserialize from Object value (missing default constructor or creator, or perhaps need to add/enable type information?)
at [Source: java.io.PushbackInputStream@3cdde747; line: 1, column: 3] (through reference chain: java.util.ArrayList[0])] with root cause
com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of com.kanshu.dao.model.User: no suitable constructor found, can not deserialize from Object value (missing default constructor or creator, or perhaps need to add/enable type information?)
at [Source: java.io.PushbackInputStream@3cdde747; line: 1, column: 3] (through reference chain: java.util.ArrayList[0])
原因:结果json无法转换导致的
解决:将返回类型转换为Object然后在转换为响应类型即可
 
Eureka错误:
1:
问题:
com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused: connect
或者com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
原因:
在默认设置下,Eureka服务注册中心也会将自己作为客户端来尝试注册它自己,所以我们需要禁用它的客户端注册行为。
禁止方式如下:在application.properties配置文件中增加以下内容
解决:
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
 
 
 
SpringBoot Config整合:
1:
问题:
搭建启动时候报错: You need to configure a uri for the git repository  
原因:
最后发现在application.properties 中使用了spring.profiles.active=test  导致test 配置文件的spring.profiles.active  失效,就变成了默认从git 上读取,所以才会报错.
解决:
spring.profiles.active=native
 
后期持续更新
posted @ 2019-03-23 22:31  杏仁拌饭  阅读(196)  评论(0)    收藏  举报