热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

0.9.0.RELEASE版本的springcloudalibabanacos实例

简而言之,nacos与eureka的不同之处有三:后台老板、部署方式、功能。nacos是阿里的,eureka是奈飞的;nacos有自己的安装包,需要独立部署,eureka仅作为一个

  简而言之,nacos与eureka的不同之处有三:后台老板、部署方式、功能。nacos是阿里的,eureka是奈飞的;nacos有自己的安装包,需要独立部署,eureka仅作为一个服务组件,引入jar包即可;nacos=eureka+config,它既是注册中心,也是配置中心。

  如何使用nacos?先下载安装包(下载地址https://github.com/alibaba/nacos/releases),打开下载页 -> 点击目前最新版本1.1.3跳到下载页 -> 点击压缩包 -> 下载到本地(E盘download目录)后解压 -> 通过命令行启动nacos:

C:\Users\wulf>e:
E:\
>cd download\nacos\bin
E:\download\nacos\bin
>startup.cmd -m standalone
,
--.
,
--.|
,--,: : | Nacos 1.1.3
,`
--.`| : ,---. Running in stand alone mode, All function modules
| : : | | ,\ .--.--. Port: 8848
:
| \ | : ,--.--. ,---. / / | / / Pid: 32916
| : ; | / \ / \. ; ,. :| : /`./ Console: http://10.10.100.110:8848/nacos/index.html
;. ;.--. .-. | / / ‘‘ | |: :| : ;_
| | | \ | \__\/: . .. / | .; : \ \ `. https://nacos.io
: | ; . ," .--.; |‘ ; :__| : | `----. \
| | `-- / / ,. | | .|\ \ / / /`-- /
: | ; : . \ : : `---- --. /
; |. | , .-./\ \ / `-----
--- `--`--- `----
2019-08-21 10:44:30,073 INFO Bean org.springframework.security.config.annotation.configuration.ObjectPostProcessorConfiguration of type [org.springframework.security.config.annotation.configuration.ObjectPostProcessorConfiguration$$EnhancerBySpringCGLIB$$209b3f7a] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-08-21 10:44:30,213 INFO Bean objectPostProcessor of type [org.springframework.security.config.annotation.configuration.AutowireBeanFactoryObjectPostProcessor] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-08-21 10:44:30,225 INFO Bean org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler@6e9175d8 of type [org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-08-21 10:44:30,234 INFO Bean org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration of type [org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration$$EnhancerBySpringCGLIB$$456fe22c] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-08-21 10:44:30,241 INFO Bean methodSecurityMetadataSource of type [org.springframework.security.access.method.DelegatingMethodSecurityMetadataSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-08-21 10:44:32,145 INFO Tomcat initialized with port(s): 8848 (http)
2019-08-21 10:44:35,148 INFO Root WebApplicationContext: initialization completed in 8513 ms
2019-08-21 10:44:40,366 INFO Initializing ExecutorService applicationTaskExecutor
2019-08-21 10:44:40,922 INFO Adding welcome page: class path resource [static/index.html]
2019-08-21 10:44:41,424 INFO Creating filter chain: Ant [pattern=/], []
2019-08-21 10:44:41,435 INFO Creating filter chain: Ant [pattern=/**/*.css], []
2019-08-21 10:44:41,435 INFO Creating filter chain: Ant [pattern=/**/*.js], []
2019-08-21 10:44:41,438 INFO Creating filter chain: Ant [pattern=/**/*.html], []
2019-08-21 10:44:41,442 INFO Creating filter chain: Ant [pattern=/**/*.map], []
2019-08-21 10:44:41,442 INFO Creating filter chain: Ant [pattern=/**/*.svg], []
2019-08-21 10:44:41,444 INFO Creating filter chain: Ant [pattern=/**/*.png], []
2019-08-21 10:44:41,444 INFO Creating filter chain: Ant [pattern=/**/*.ico], []
2019-08-21 10:44:41,444 INFO Creating filter chain: Ant [pattern=/console-fe/public/**], []
2019-08-21 10:44:41,446 INFO Creating filter chain: Ant [pattern=/v1/auth/login], []
2019-08-21 10:44:41,447 INFO Creating filter chain: Ant [pattern=/v1/console/health/**], []
2019-08-21 10:44:41,447 INFO Creating filter chain: Ant [pattern=/v1/cs/**], []
2019-08-21 10:44:41,447 INFO Creating filter chain: Ant [pattern=/v1/ns/**], []
2019-08-21 10:44:41,447 INFO Creating filter chain: Ant [pattern=/v1/cmdb/**], []
2019-08-21 10:44:41,450 INFO Creating filter chain: Ant [pattern=/actuator/**], []
2019-08-21 10:44:41,454 INFO Creating filter chain: Ant [pattern=/v1/console/server/**], []
2019-08-21 10:44:41,498 INFO Creating filter chain: any request, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@6c8bca63, org.springframework.security.web.context.SecurityContextPersistenceFilter@6d24ffa1, org.springframework.security.web.header.HeaderWriterFilter@74cadd41, org.springframework.security.web.authentication.logout.LogoutFilter@42a9e5d1, com.alibaba.nacos.console.filter.JwtAuthenticationTokenFilter@2364305a, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@773f7880, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@4c51bb7, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@470a696f, org.springframework.security.web.session.SessionManagementFilter@55e8ec2f, org.springframework.security.web.access.ExceptionTranslationFilter@62fad19, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@5536379e]
2019-08-21 10:44:41,566 INFO Exposing 2 endpoint(s) beneath base path /actuator
2019-08-21 10:44:41,616 INFO Initializing ExecutorService taskScheduler
2019-08-21 10:44:41,773 INFO Tomcat started on port(s): 8848 (http) with context path /nacos
2019-08-21 10:44:41,778 INFO Nacos Log files: E:\download\nacos/logs/
2019-08-21 10:44:41,783 INFO Nacos Conf files: E:\download\nacos/conf/
2019-08-21 10:44:41,783 INFO Nacos Data files: E:\download\nacos/data/
2019-08-21 10:44:41,784 INFO Nacos started successfully in stand alone mode.
2019-08-21 10:44:44,665 INFO Initializing Servlet dispatcherServlet
2019-08-21 10:44:44,686 INFO Completed initialization in 20 ms

  我们通过localhost:8848/nacos可以访问到它,默认用户名密码都是nacos:

技术分享图片

  我们创建个项目来注册到这个nacos,三板斧又来了:

  1、pom引入spring boot、spring cloud、spring cloud alibaba和nacos:


org.springframework.boot
spring-boot-starter-parent
2.1.7.RELEASE



org.springframework.cloud
spring-cloud-dependencies
Greenwich.SR2
pom
import


org.springframework.cloud
spring-cloud-alibaba-dependencies
0.9.0.RELEASE
pom
import


org.springframework.cloud
spring-cloud-starter-alibaba-nacos-discovery



  2、application:

#端口
server.port
=8282
#应用名
spring.application.name
=lxytrans-provider
#注册中心
spring.cloud.nacos.discovery.server
-addr=localhost:8848

  3、启动类加注解:

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@EnableDiscoveryClient
@SpringBootApplication
public class TransProviderApplication {
public static void main(String[] args) {
SpringApplication.run(TransProviderApplication.
class, args);
}
@Slf4j
@RestController
static class TestController {
@GetMapping(
"/hello")
public String hello() {
return "hello";
}
@GetMapping(
"/hey")
public String hey() throws InterruptedException {
Thread.sleep(
2000);
return "hey";
}
}
}

  跑起来后我们看下nacos控制台实例:

技术分享图片

 

  

 


推荐阅读
  • Java验证码——kaptcha的使用配置及样式
    本文介绍了如何使用kaptcha库来实现Java验证码的配置和样式设置,包括pom.xml的依赖配置和web.xml中servlet的配置。 ... [详细]
  • 基于layUI的图片上传前预览功能的2种实现方式
    本文介绍了基于layUI的图片上传前预览功能的两种实现方式:一种是使用blob+FileReader,另一种是使用layUI自带的参数。通过选择文件后点击文件名,在页面中间弹窗内预览图片。其中,layUI自带的参数实现了图片预览功能。该功能依赖于layUI的上传模块,并使用了blob和FileReader来读取本地文件并获取图像的base64编码。点击文件名时会执行See()函数。摘要长度为169字。 ... [详细]
  • HDU 2372 El Dorado(DP)的最长上升子序列长度求解方法
    本文介绍了解决HDU 2372 El Dorado问题的一种动态规划方法,通过循环k的方式求解最长上升子序列的长度。具体实现过程包括初始化dp数组、读取数列、计算最长上升子序列长度等步骤。 ... [详细]
  • 本文讨论了Alink回归预测的不完善问题,指出目前主要针对Python做案例,对其他语言支持不足。同时介绍了pom.xml文件的基本结构和使用方法,以及Maven的相关知识。最后,对Alink回归预测的未来发展提出了期待。 ... [详细]
  • 本文讨论了如何优化解决hdu 1003 java题目的动态规划方法,通过分析加法规则和最大和的性质,提出了一种优化的思路。具体方法是,当从1加到n为负时,即sum(1,n)sum(n,s),可以继续加法计算。同时,还考虑了两种特殊情况:都是负数的情况和有0的情况。最后,通过使用Scanner类来获取输入数据。 ... [详细]
  • 本文介绍了OC学习笔记中的@property和@synthesize,包括属性的定义和合成的使用方法。通过示例代码详细讲解了@property和@synthesize的作用和用法。 ... [详细]
  • Mac OS 升级到11.2.2 Eclipse打不开了,报错Failed to create the Java Virtual Machine
    本文介绍了在Mac OS升级到11.2.2版本后,使用Eclipse打开时出现报错Failed to create the Java Virtual Machine的问题,并提供了解决方法。 ... [详细]
  • 本文介绍了在SpringBoot中集成thymeleaf前端模版的配置步骤,包括在application.properties配置文件中添加thymeleaf的配置信息,引入thymeleaf的jar包,以及创建PageController并添加index方法。 ... [详细]
  • 本文讲述了作者通过点火测试男友的性格和承受能力,以考验婚姻问题。作者故意不安慰男友并再次点火,观察他的反应。这个行为是善意的玩人,旨在了解男友的性格和避免婚姻问题。 ... [详细]
  • 1,关于死锁的理解死锁,我们可以简单的理解为是两个线程同时使用同一资源,两个线程又得不到相应的资源而造成永无相互等待的情况。 2,模拟死锁背景介绍:我们创建一个朋友 ... [详细]
  • 《数据结构》学习笔记3——串匹配算法性能评估
    本文主要讨论串匹配算法的性能评估,包括模式匹配、字符种类数量、算法复杂度等内容。通过借助C++中的头文件和库,可以实现对串的匹配操作。其中蛮力算法的复杂度为O(m*n),通过随机取出长度为m的子串作为模式P,在文本T中进行匹配,统计平均复杂度。对于成功和失败的匹配分别进行测试,分析其平均复杂度。详情请参考相关学习资源。 ... [详细]
  • 动态规划算法的基本步骤及最长递增子序列问题详解
    本文详细介绍了动态规划算法的基本步骤,包括划分阶段、选择状态、决策和状态转移方程,并以最长递增子序列问题为例进行了详细解析。动态规划算法的有效性依赖于问题本身所具有的最优子结构性质和子问题重叠性质。通过将子问题的解保存在一个表中,在以后尽可能多地利用这些子问题的解,从而提高算法的效率。 ... [详细]
  • 高质量SQL书写的30条建议
    本文提供了30条关于优化SQL的建议,包括避免使用select *,使用具体字段,以及使用limit 1等。这些建议是基于实际开发经验总结出来的,旨在帮助读者优化SQL查询。 ... [详细]
  • 在project.properties添加#Projecttarget.targetandroid-19android.library.reference.1..Sliding ... [详细]
  • 本文介绍了一种解析GRE报文长度的方法,通过分析GRE报文头中的标志位来计算报文长度。具体实现步骤包括获取GRE报文头指针、提取标志位、计算报文长度等。该方法可以帮助用户准确地获取GRE报文的长度信息。 ... [详细]
author-avatar
45仰望易_332
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有