springcloud-alibaba报错笔记

导读:本篇文章讲解 springcloud-alibaba报错笔记,希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com

1.使用ribbon报错如下:

java.net.UnknownHostException: nacos-provider
	at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:564) ~[na:na]
	at java.base/java.net.Socket.connect(Socket.java:633) ~[na:na]
	at java.base/java.net.Socket.connect(Socket.java:583) ~[na:na]
	at java.base/sun.net.NetworkClient.doConnect(NetworkClient.java:183) ~[na:na]
	at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:498) ~[na:na]
	at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:603) ~[na:na]
	at java.base/sun.net.www.http.HttpClient.<init>(HttpClient.java:246) ~[na:na]
	at java.base/sun.net.www.http.HttpClient.New(HttpClient.java:351) ~[na:na]
	at java.base/sun.net.www.http.HttpClient.New(HttpClient.java:373) ~[na:na]
	

导致的原因为alibaba不再支持netflix的ribbon所以需要手动导入如下包:

<dependency>
     <groupId>org.springframework.cloud</groupId>
     <artifactId>spring-cloud-starter-loadbalancer</artifactId>
     <version>3.1.4</version>
</dependency>

同时在pom文件导入alibaba-nacos处排除掉netflix-ribbon

        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.cloud</groupId>
                    <artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

最后在application.yml中配置一下,完全禁用ribbon

spring:
  application:
    name: nacos-consumer
  cloud:
    loadbalancer:
      ribbon:
        enabled: false
    nacos:
      discovery:
        server-addr: localhost:8848

2.nacos修改数据源为mysql报错 nodatasource

Caused by: java.lang.IllegalStateException: No DataSource set
	at org.springframework.util.Assert.state(Assert.java:73)
	at org.springframework.jdbc.support.JdbcAccessor.obtainDataSource(JdbcAccessor.java:77)
	at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:371)
	at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:452)
	at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:462)
	at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:473)
	at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:480)
	at com.alibaba.nacos.config.server.service.repository.extrnal.ExternalStoragePersistServiceImpl.findConfigMaxId(ExternalStoragePersistServiceImpl.java:667)
	at com.alibaba.nacos.config.server.service.dump.processor.DumpAllProcessor.process(DumpAllProcessor.java:51)
	at com.alibaba.nacos.config.server.service.dump.DumpService.dumpConfigInfo(DumpService.java:282)
	at com.alibaba.nacos.config.server.service.dump.DumpService.dumpOperate(DumpService.java:195)
	... 61 common frames omitted

原因:新版数据库驱动需要加上时区

spring.datasource.platform=mysql

db.num=1
db.url.0=jdbc:mysql://localhost:3306/nacos_devtest?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&serverTimezone=UTC
db.user=root
db.password=123456

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/88866.html

(0)
小半的头像小半

相关推荐

极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!