SpringCloud 微服务常见错误

最近在做微服务项目,打算记录一下遇到的错误。这些错误会在遇到时慢慢添加上去


1.

Consider the following:
	If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
	If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

      一般遇到这个错是因为你在springboot的父目录的pom.xml里导入了跟数据库连接相关的jar,但消费者处的项目不需要使用这些jar,所以产生了冲突,可以在开关类处加上@SpringBootApplication(exclude = DataSourceAutoConfiguration.class) 将不需要的包排除掉,或者在主程序的pom.xml里把相关的jar去掉也行。


2.

java.net.SocketTimeoutException: connect timed out
	at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method) ~[na:1.8.0_161]
	at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85) ~[na:1.8.0_161]
	at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[na:1.8.0_161]
	at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[na:1.8.0_161]
	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[na:1.8.0_161]

报这个错代表连接超时,一般是电脑配置的问题,电脑配置比较差的话,容易出现连接超时,所以在开发时可以在消费者里写一个配置类改变默认的连接时间。代码如下:

@Configuration
public class FeignConfig {
    private int connecttimeout=20000; //20秒
    private int readtimeout=20000; // 20秒

    @Bean
    public Request.Options createOp() {
        return new Request.Options(connecttimeout, readtimeout);
    }
}

3.

***************************
APPLICATION FAILED TO START
***************************

Description:

The bean 'UserService.FeignClientSpecification', defined in null, could not be registered. A bean with that name has already been defined in null and overriding is disabled.

Action:

Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true


Process finished with exit code 1

 报上面这个错,是为了节约资源所以在同一个消费者里面写了多个service,然后调用同一个FeignClientSpecification,所以注册时出现了冲突,导致报错,解决方案是重新调用另一个提供着,或者在applicantion.yml里加入:spring.main.allow-bean-definition-overriding:true即可,允许覆盖。如下所示。

server:
  port: 8801
spring:
  application:
    name: UserApi
  profiles:
    active: dev  #dev开发环境  test测试环境 prod生产环境(线上环境)
  main:
    allow-bean-definition-overriding: true

 

你可能感兴趣的:(Java)