daxian-zhu / online-edu-star

96 stars 51 forks source link

Application failed to connect to Nacos server: "" #1

Open 747857485 opened 4 years ago

747857485 commented 4 years ago

大佬,学历微服务中,Nacos 的远程配置文件我关闭了,为什么总是提示说是找不到Nacos 配置文件?

daxian-zhu commented 4 years ago

首先,你这个不是配置文件拉不下来的问题,是因为连不上的nacos的问题。 请做以下确认: 1、nacos是否已经启动 2、nacos的连接地址是否正确(在bootstrap.yml里面进行确认) 3、是否配置了nacos的连接地址

zhuwei680913@163.com

From: 747857485 Date: 2020-03-09 14:45 To: daxian-zhu/online-edu-star CC: Subscribed Subject: [daxian-zhu/online-edu-star] Application failed to connect to Nacos server: "" (#1) 大佬,学历微服务中,Nacos 的远程配置文件我关闭了,为什么总是提示说是找不到Nacos 配置文件? — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

747857485 commented 4 years ago

server: port: 8663 spring: application: name: oauth2-server cloud: nacos: discovery: server-addr: 127.0.0.1:8848

config:

server-addr: 127.0.0.1:8848

file-extension: yaml

redis配置

redis: host: 127.0.0.1 password: port: 6379 database: 0 timeout: 60000 edu: auth: server: maxClient: 30000 tokenValid: 14400 force: false startRefresh: false keyPath: classpath:kevin_key.jks alias: wecode secret: wecodeCloud

sharding-jdbc读写分离的配置 ,如果不想读写分离配置,设置2个数据库同源即可

sharding.jdbc: data-sources: ds_master: driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://127.0.0.1:3306/edu_user?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8 username: root password: password ds_slave_0: driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://127.0.0.1:3306/edu_user?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8 username: root password: password master-slave-rule: name: ds_ms master-data-source-name: ds_master slave-data-source-names: ds_slave_0 load-balance-algorithm-type: round_robin props: sql.show: true

mybatis的配置

mybatis: configuration: log-impl: org.apache.ibatis.logging.stdout.StdOutImpl 感谢回复。这是我修改后的配置文件。nacos 没问题,因为我别的项目可以注册上来。不知道你这个框架是不是哪还需要修改呢?

daxian-zhu commented 4 years ago

才看到,注释掉yml中的config配置的同时,也需要注解 因为源码里面有默认配置。 当然,注释之后别忘记刷新下maven的缓存。

zhuwei680913@163.com

From: 747857485 Date: 2020-03-09 15:00 To: daxian-zhu/online-edu-star CC: 大仙; Comment Subject: Re: [daxian-zhu/online-edu-star] Application failed to connect to Nacos server: "" (#1) server: port: 8663 spring: application: name: oauth2-server cloud: nacos: discovery: server-addr: 127.0.0.1:8848

config:

server-addr: 127.0.0.1:8848

file-extension: yaml

redis配置

redis: host: 127.0.0.1 password: port: 6379 database: 0 timeout: 60000 edu: auth: server: maxClient: 30000 tokenValid: 14400 force: false startRefresh: false keyPath: classpath:kevin_key.jks alias: wecode secret: wecodeCloud

sharding-jdbc读写分离的配置 ,如果不想读写分离配置,设置2个数据库同源即可

sharding.jdbc: data-sources: ds_master: driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://127.0.0.1:3306/edu_user?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8 username: root password: password ds_slave_0: driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://127.0.0.1:3306/edu_user?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8 username: root password: password master-slave-rule: name: ds_ms master-data-source-name: ds_master slave-data-source-names: ds_slave_0 load-balance-algorithm-type: round_robin props: sql.show: true

mybatis的配置

mybatis: configuration: log-impl: org.apache.ibatis.logging.stdout.StdOutImpl 感谢回复。这是我修改后的配置文件。nacos 没问题,因为我别的项目可以注册上来。不知道你这个框架是不是哪还需要修改呢? — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

747857485 commented 4 years ago

还是不行,我想问一下,如果我不注释的话,是不是要在nacos里加一些配置呢?

daxian-zhu commented 4 years ago

你注释掉config配置之后

需要刷新下maven。我这边启动了是没问题的 其他的gateway的配置如下:主要是开放端点,指定hsytrix的隔离策略等配置,不太影响整个项目 management: endpoints: web: exposure: include: "*" endpoint: health: show-details: ALWAYS feign: hystrix: enabled: true ribbon: ConnectTimeout: 10000 ReadTimeout: 10000 hystrix: command:

default全局有效,service id指定应用有效

default:
  execution:
    timeout:
      #如果enabled设置为false,则请求超时交给ribbon控制,为true,则超时作为熔断根据
      enabled: true
    isolation:
      thread:
        timeoutInMilliseconds: 40000
      #设置隔离策略,信号针
      strategy: SEMAPHORE

spring: servlet: multipart: max-file-size: 5MB

zhuwei680913@163.com

From: 747857485 Date: 2020-03-09 15:46 To: daxian-zhu/online-edu-star CC: 大仙; Comment Subject: Re: [daxian-zhu/online-edu-star] Application failed to connect to Nacos server: "" (#1) 还是不行,我想问一下,如果我不注释的话,是不是要在nacos里加一些配置呢? — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

747857485 commented 4 years ago

谢谢,可以了,原来是因为没设置使用的yml类型。有帮助文档之类的吗?从头看代码量有点多....😂

daxian-zhu commented 4 years ago

https://blog.csdn.net/zhuwei_clark 在整理,可以先看博客,博客上面有从头开始的说明

zhuwei680913@163.com

From: 747857485 Date: 2020-03-09 16:15 To: daxian-zhu/online-edu-star CC: 大仙; Comment Subject: Re: [daxian-zhu/online-edu-star] Application failed to connect to Nacos server: "" (#1) 谢谢,可以了,原来是因为没设置使用的yml类型。有帮助文档之类的吗?从头看代码量有点多....???? — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

747857485 commented 4 years ago

我是说数据库的测试数据....

------------------ 原始邮件 ------------------ 发件人: "大仙"<notifications@github.com>; 发送时间: 2020年3月9日(星期一) 下午4:26 收件人: "daxian-zhu/online-edu-star"<online-edu-star@noreply.github.com>; 抄送: "郭凯"<747857485@qq.com>; "Author"<author@noreply.github.com>; 主题: Re: [daxian-zhu/online-edu-star] Application failed to connect to Nacos server: "" (#1)

https://blog.csdn.net/zhuwei_clark 在整理,可以先看博客,博客上面有从头开始的说明

zhuwei680913@163.com

From: 747857485 Date: 2020-03-09 16:15 To: daxian-zhu/online-edu-star CC: 大仙; Comment Subject: Re: [daxian-zhu/online-edu-star] Application failed to connect to Nacos server: "" (#1) 谢谢,可以了,原来是因为没设置使用的yml类型。有帮助文档之类的吗?从头看代码量有点多....????
— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

daxian-zhu commented 4 years ago

https://github.com/daxian-zhu/online-edu-star/blob/master/docs/edu_user.sql

zhuwei680913@163.com

From: 747857485 Date: 2020-03-09 16:32 To: daxian-zhu/online-edu-star CC: 大仙; Comment Subject: Re: [daxian-zhu/online-edu-star] Application failed to connect to Nacos server: "" (#1) 我是说数据库的测试数据....

------------------ 原始邮件 ------------------ 发件人: "大仙"<notifications@github.com>; 发送时间: 2020年3月9日(星期一) 下午4:26 收件人: "daxian-zhu/online-edu-star"<online-edu-star@noreply.github.com>; 抄送: "郭凯"<747857485@qq.com>; "Author"<author@noreply.github.com>; 主题: Re: [daxian-zhu/online-edu-star] Application failed to connect to Nacos server: "" (#1)

https://blog.csdn.net/zhuwei_clark 在整理,可以先看博客,博客上面有从头开始的说明

zhuwei680913@163.com

From: 747857485 Date: 2020-03-09 16:15 To: daxian-zhu/online-edu-star CC: 大仙; Comment Subject: Re: [daxian-zhu/online-edu-star] Application failed to connect to Nacos server: "" (#1) 谢谢,可以了,原来是因为没设置使用的yml类型。有帮助文档之类的吗?从头看代码量有点多....???? — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe. — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

747857485 commented 4 years ago
image

密码模式为什么显示没有用户呢?库里面明明有啊,另外几种 openiid 电话号码等登录方式怎么用呢?研究了一天没研究明白😂

daxian-zhu commented 4 years ago

登录是用邮箱的,不是用用户名的。 扩展登录方式:https://blog.csdn.net/zhuwei_clark/article/details/103980279

zhuwei680913@163.com

From: 747857485 Date: 2020-03-10 08:34 To: daxian-zhu/online-edu-star CC: 大仙; Comment Subject: Re: [daxian-zhu/online-edu-star] Application failed to connect to Nacos server: "" (#1) 密码模式为什么显示没有用户呢?库里面明明有啊,另外几种 openiid 电话号码等登录方式怎么用呢?研究了一天没研究明白???? — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

747857485 commented 4 years ago

麻烦了,大佬。GateWay 的路由里面我放了资源服务器,但是为什么我请求路由的时候总是返回403呢? 求指点..... server: port: 8661 spring: application: name: gateway cloud: nacos: discovery: server-addr: 127.0.0.1:8848 gateway: discovery: locator: enabled: true routes:

daxian-zhu commented 4 years ago

资源服务器不是单独的服务,你在gateway里面引入资源服务器的配置之后,gateway就是资源服务器。所以你那个lb://oauth2-resource 完全是没必要的。 然后,请求的权限控制在WebfluxReactiveAuthorizationManager

zhuwei680913@163.com

From: 747857485 Date: 2020-03-12 14:22 To: daxian-zhu/online-edu-star CC: 大仙; Comment Subject: Re: [daxian-zhu/online-edu-star] Application failed to connect to Nacos server: "" (#1) 麻烦了,大佬。GateWay 的路由里面我放了资源服务器,但是为什么我请求路由的时候总是返回403呢? 求指点..... server: port: 8661 spring: application: name: gateway cloud: nacos: discovery: server-addr: 127.0.0.1:8848 gateway: discovery: locator: enabled: true routes:

security: oauth2: resourceserver: jwt: jwk-set-uri: http://localhost:8663/pub-key/jwt.json edu: security: ignored: | /favicon.ico, /user/v2/api-docs/,/user/webjars/,/user/swagger-resources/,/user/*.html, /im/v2/api-docs/,/im/webjars/,/im/swagger-resources/*,/im/.html, /auth/login,/oauth2-server/,/oauth2-resource/** notRole: | /user,/user/permission/all — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

747857485 commented 4 years ago

我的想法是,通过网关过滤所有资源请求,这样,我只需要在网关配置就行了。不然的话,我每写一个资源都需要再写一次。太麻烦了。相当于把网关作为整个项目的过滤器

daxian-zhu commented 4 years ago

我说的就是网关继承认证啊,授权判断的类我刚告诉你了啊

发自我的iPhone

在 2020年3月12日,14:33,747857485 notifications@github.com 写道:

 我的想法是,通过网关过滤所有资源请求,这样,我只需要在网关配置就行了。不然的话,我每写一个资源都需要再写一次。太麻烦了。相当于把网关作为整个项目的过滤器 — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

daxian-zhu commented 4 years ago

我的想法是,通过网关过滤所有资源请求,这样,我只需要在网关配置就行了。不然的话,我每写一个资源都需要再写一次。太麻烦了。相当于把网关作为整个项目的过滤器

你认证看下代码吧,资源服务器封装成了auth-spring-boot-starter。你在网关引入了即可,在starter里面有一个授权控制类:WebfluxReactiveAuthorizationManager 这个是类是控制所有的访问的配置,如果这个类判断没权限就会返回403

747857485 commented 4 years ago

厄..,可能是我问的不太对。等你方便的时候再详细请教。那个类我找到了,我把资源服务器的链接直接放过了。断点看过你说的类了,通过了。但是不知道什么地方,又给拦截了,返回的403的json

------------------ 原始邮件 ------------------ 发件人: "大仙"<notifications@github.com>; 发送时间: 2020年3月12日(星期四) 下午2:57 收件人: "daxian-zhu/online-edu-star"<online-edu-star@noreply.github.com>; 抄送: "郭凯"<747857485@qq.com>; "Author"<author@noreply.github.com>; 主题: Re: [daxian-zhu/online-edu-star] Application failed to connect to Nacos server: "" (#1)

我的想法是,通过网关过滤所有资源请求,这样,我只需要在网关配置就行了。不然的话,我每写一个资源都需要再写一次。太麻烦了。相当于把网关作为整个项目的过滤器

你认证看下代码吧,资源服务器封装成了auth-spring-boot-starter。你在网关引入了即可,在starter里面有一个授权控制类:WebfluxReactiveAuthorizationManager 这个是类是控制所有的访问的配置,如果这个类判断没权限就会返回403

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.