很多java的朋友学习新知识时候去百度,看了之后一知半解,不知道怎么操作,不知道到底什么什么东西,那么作为java码农到底该怎么学习额  

一  百度是对还是错呢?

  百度是一个万能的工具,当然是对也是错的,对于一些小知识,是可以百度的,但是例如学习springcloud,那么最好是进入官方文档进行查看,可以清晰查看到当前版本信息

因为很多时候,在版本迭代时候出现问题,那么看官方文档就可以很清晰知道这个问题。

  那么问题来了,英文不好,怎么处理?

  不用太担心,可以使用翻译工具:

  

可能有时候不准,但是我们作为程序员的应该知道如何处理,将不懂的单词进行留意,再去看文档。

二 看文档搭建eureka注册中心:

首先进入springcloud官网,eureka是netlex公司开发的,所以进入找相关模块,当然也有阿里巴巴的,

https://cloud.spring.io/spring-cloud-static/spring-cloud-netflix/2.1.3.RELEASE/single/spring-cloud-netflix.html#netflix-eureka-server-starter

再找模块

Service Discovery: Eureka Server

相信大家知道这个什么意思了,服务发现,eureka服务端

我们可以使用idea去创建项目,

主pom,进行依赖控制,当然也可以这样,将他们分开,进行单独项目进行配置,那么可以单独建立,一个就不能拿到公司的所有的项目

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  4. <modelVersion>4.0.</modelVersion>
  5. <packaging>pom</packaging>
  6. <modules>
  7. <module>springrurekaserver</module>
  8. </modules>
  9. <parent>
  10. <groupId>org.springframework.boot</groupId>
  11. <artifactId>spring-boot-starter-parent</artifactId>
  12. <version>2.1..RELEASE</version>
  13. <relativePath/> <!-- lookup parent from repository -->
  14. </parent>
  15. <groupId>com.cxy</groupId>
  16. <artifactId>springcloudlearning</artifactId>
  17. <version>0.0.-SNAPSHOT</version>
  18. <name>springcloudlearning</name>
  19. <description>Demo project for Spring Boot</description>
  20.  
  21. <properties>
  22. <java.version>1.8</java.version>
  23. <spring-cloud.version>Greenwich.SR3</spring-cloud.version>
  24. </properties>
  25.  
  26. <dependencies>
  27. <dependency>
  28. <groupId>org.springframework.boot</groupId>
  29. <artifactId>spring-boot-starter-test</artifactId>
  30. </dependency>
  31. </dependencies>
  32.  
  33. <dependencyManagement>
  34. <dependencies>
  35. <dependency>
  36. <groupId>org.springframework.cloud</groupId>
  37. <artifactId>spring-cloud-dependencies</artifactId>
  38. <version>${spring-cloud.version}</version>
  39. <type>pom</type>
  40. <scope>import</scope>
  41. </dependency>
  42. </dependencies>
  43. </dependencyManagement>
  44.  
  45. <build>
  46. <plugins>
  47. <plugin>
  48. <groupId>org.springframework.boot</groupId>
  49. <artifactId>spring-boot-maven-plugin</artifactId>
  50. </plugin>
  51. </plugins>
  52. </build>
  53.  
  54. <!--<repositories>
  55. <repository>
  56. <id>spring-milestones</id>
  57. <name>Spring Milestones</name>
  58. <url>https://repo.spring.io/milestone</url>
  59. </repository>
  60. </repositories>-->
  61.  
  62. </project>
  1. <!--<repositories>
  2. <repository>
  3. <id>spring-milestones</id>
  4. <name>Spring Milestones</name>
  5. <url>https://repo.spring.io/milestone</url>
  6. </repository>
  7. </repositories>-->

这个部分为什么注释呢,由于在选版本时候,idea自己给我选择了版本,所以带出来了,官网这个不安全的版本。

然后参照官方:

引入依赖,所以这里就引入依赖:

然后再创建application。yml

  1. server:
  2. port:
  3.  
  4. eureka:
  5. instance:
  6. hostname: localhost
  7. client:
  8. registerWithEureka: false
  9. fetchRegistry: false
  10. serviceUrl:
  11. defaultZone: http://127.0.0.1:8761/eureka/

然后再创建

  1. package com.cxy;
  2.  
  3. import org.springframework.boot.Banner;
  4. import org.springframework.boot.SpringApplication;
  5. import org.springframework.boot.SpringBootVersion;
  6. import org.springframework.boot.WebApplicationType;
  7. import org.springframework.boot.autoconfigure.SpringBootApplication;
  8. import org.springframework.boot.builder.SpringApplicationBuilder;
  9. import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
  10.  
  11. @SpringBootApplication
  12. @EnableEurekaServer
  13. public class EurekaApplication {
  14. public static void main(String[] args) {
  15. new SpringApplicationBuilder(EurekaApplication.class)
  16. // .web(WebApplicationType.SERVLET)
  17. .main(SpringBootVersion.class)
  18. .run(args);
  19. /*
  20. SpringApplicationBuilder springApplicationBuilder = new SpringApplicationBuilder(EnableEurekaServer.class);
  21. SpringApplicationBuilder web = springApplicationBuilder.web(webappl);
  22. web.run(args);
  23. */
  24.  
  25. SpringApplication.run(EurekaApplication.class,args);
  26. }
  27. }

可以看下官方:

其实在那个web方法地方的时候会报错,所以我们需要点进源码看下:

传入了一个webApplicationType

这个是什么东西呢:

  1. /*
  2. * Copyright 2012-2019 the original author or authors.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * https://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16.  
  17. package org.springframework.boot;
  18.  
  19. import org.springframework.util.ClassUtils;
  20.  
  21. /**
  22. * An enumeration of possible types of web application.
  23. *
  24. * @author Andy Wilkinson
  25. * @author Brian Clozel
  26. * @since 2.0.0
  27. */
  28. public enum WebApplicationType {
  29.  
  30. /**
  31. * The application should not run as a web application and should not start an
  32. * embedded web server.
  33. */
  34. NONE,
  35.  
  36. /**
  37. * The application should run as a servlet-based web application and should start an
  38. * embedded servlet web server.
  39. */
  40. SERVLET,
  41.  
  42. /**
  43. * The application should run as a reactive web application and should start an
  44. * embedded reactive web server.
  45. */
  46. REACTIVE;
  47.  
  48. private static final String[] SERVLET_INDICATOR_CLASSES = { "javax.servlet.Servlet",
  49. "org.springframework.web.context.ConfigurableWebApplicationContext" };
  50.  
  51. private static final String WEBMVC_INDICATOR_CLASS = "org.springframework." + "web.servlet.DispatcherServlet";
  52.  
  53. private static final String WEBFLUX_INDICATOR_CLASS = "org." + "springframework.web.reactive.DispatcherHandler";
  54.  
  55. private static final String JERSEY_INDICATOR_CLASS = "org.glassfish.jersey.servlet.ServletContainer";
  56.  
  57. private static final String SERVLET_APPLICATION_CONTEXT_CLASS = "org.springframework.web.context.WebApplicationContext";
  58.  
  59. private static final String REACTIVE_APPLICATION_CONTEXT_CLASS = "org.springframework.boot.web.reactive.context.ReactiveWebApplicationContext";
  60.  
  61. static WebApplicationType deduceFromClasspath() {
  62. if (ClassUtils.isPresent(WEBFLUX_INDICATOR_CLASS, null) && !ClassUtils.isPresent(WEBMVC_INDICATOR_CLASS, null)
  63. && !ClassUtils.isPresent(JERSEY_INDICATOR_CLASS, null)) {
  64. return WebApplicationType.REACTIVE;
  65. }
  66. for (String className : SERVLET_INDICATOR_CLASSES) {
  67. if (!ClassUtils.isPresent(className, null)) {
  68. return WebApplicationType.NONE;
  69. }
  70. }
  71. return WebApplicationType.SERVLET;
  72. }
  73.  
  74. static WebApplicationType deduceFromApplicationContext(Class<?> applicationContextClass) {
  75. if (isAssignable(SERVLET_APPLICATION_CONTEXT_CLASS, applicationContextClass)) {
  76. return WebApplicationType.SERVLET;
  77. }
  78. if (isAssignable(REACTIVE_APPLICATION_CONTEXT_CLASS, applicationContextClass)) {
  79. return WebApplicationType.REACTIVE;
  80. }
  81. return WebApplicationType.NONE;
  82. }
  83.  
  84. private static boolean isAssignable(String target, Class<?> type) {
  85. try {
  86. return ClassUtils.resolveClassName(target, null).isAssignableFrom(type);
  87. }
  88. catch (Throwable ex) {
  89. return false;
  90. }
  91. }
  92.  
  93. }

枚举类,所以看下注释:

找到了第二种,可以看下,所以传入这个类型,

当然也可以采用其他方式进行:

例如:

官方启动会构建很多东西,可以加载spring的版本,还有配置,这些:

看官方文档学习springcloud搭建的更多相关文章

  1. Spring 4 官方文档学习(十二)View技术

    关键词:view technology.template.template engine.markup.内容较多,按需查用即可. 介绍 Thymeleaf Groovy Markup Template ...

  2. Spring 4 官方文档学习(十一)Web MVC 框架之resolving views 解析视图

    接前面的Spring 4 官方文档学习(十一)Web MVC 框架,那篇太长,故另起一篇. 针对web应用的所有的MVC框架,都会提供一种呈现views的方式.Spring提供了view resolv ...

  3. Spring 4 官方文档学习(十一)Web MVC 框架

    介绍Spring Web MVC 框架 Spring Web MVC的特性 其他MVC实现的可插拔性 DispatcherServlet 在WebApplicationContext中的特殊的bean ...

  4. Spring Boot 官方文档学习(一)入门及使用

    个人说明:本文内容都是从为知笔记上复制过来的,样式难免走样,以后再修改吧.另外,本文可以看作官方文档的选择性的翻译(大部分),以及个人使用经验及问题. 其他说明:如果对Spring Boot没有概念, ...

  5. Spring Framework 官方文档学习(四)之Validation、Data Binding、Type Conversion(一)

    题外话:本篇是对之前那篇的重排版.并拆分成两篇,免得没了看的兴趣. 前言 在Spring Framework官方文档中,这三者是放到一起讲的,但没有解释为什么放到一起.大概是默认了读者都是有相关经验的 ...

  6. Spring Framework 官方文档学习(四)之Validation、Data Binding、Type Conversion(二)

    接前一篇 Spring Framework 官方文档学习(四)之Validation.Data Binding.Type Conversion(一) 本篇主要内容:Spring Type Conver ...

  7. Spring boot官方文档学习(一)

    个人说明:本文内容都是从为知笔记上复制过来的,样式难免走样,以后再修改吧.另外,本文可以看作官方文档的选择性的翻译(大部分),以及个人使用经验及问题. 其他说明:如果对Spring Boot没有概念, ...

  8. Spring Framework 官方文档学习(四)之Validation、Data Binding、Type Conversion

    本篇太乱,请移步: Spring Framework 官方文档学习(四)之Validation.Data Binding.Type Conversion(一) 写了删删了写,反复几次,对自己的描述很不 ...

  9. 根据ThinkPHP官方文档学习opensns框架

    根据ThinkPHP官方文档学习opensns框架 1.解读Application下各个Controller文件夹下的作用 控制器类的命名方式是:控制器名(驼峰法,首字母大写)+Controller ...

随机推荐

  1. java中的三大特性

    java的三大特性是封装.继承.多态: 继承是OOD(面向对象设计)为了更好的建模,编程的时候是OOP(面向对象编程)提高代码的复用性.这里有个注意点:一个类只有一个直接的父类,但不是只有一个父类. ...

  2. 为什么javaBean要有get/set方法的设计

    可以应对将来的修改,比如有一个以长度计算的项目开发好了,过段时间客户说这个项目要在美国上市,有了javaBean只要把所有以厘米计算的单位都乘以2.54转化为正确单位交给客户 public class ...

  3. CVE-2019-14287_sudo权限提升

    影响范围 sudo是linux下普通用户使用root权限的命令,sudo配置文件中使用 ALL 语句,可以使普通账号通过vim执行root权限命令. 影响 sudo 1.8.28 之前的所有版本. 漏 ...

  4. # Python第十节 传参

    Python第十节 传参 一. 变量和变量名 首先说明变量名和变量的一点差异 例如: var = [1, 2, 3] `var = "Google" 调用变量var的时候, 既可以 ...

  5. Javascript基础二(程序的三大结构)

    程序的三大结构: 顺序结构,选择结构,循环结构 程序的单分支结构-if语句:       当条件判断为真true时,执行花括号内的语句,如果条件为假false,跳过花括号内的语句       if(条 ...

  6. JS window对象 返回下一个浏览的页面 forward()方法,加载 history 列表中的下一个 URL。

    返回下一个浏览的页面 forward()方法,加载 history 列表中的下一个 URL. 如果倒退之后,再想回到倒退之前浏览的页面,则可以使用forward()方法,代码如下: window.hi ...

  7. 记录ajax前后交互

    前台请求 $.ajax({ url : '/turn', type : "post", data : { "userName":userName, " ...

  8. dubbo-源码阅读之服务订阅

    配置例子 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://w ...

  9. git的一些简单用法

    1.工作区暂存区和仓库区 工作区 对于添加.修改.删除文件的操作,都发生在工作区中 暂存区 暂存区指将工作区中的操作完成小阶段的存储,是版本库的一部分 仓库区 仓库区表示个人开发的一个小阶段的完成 仓 ...

  10. Android AppCompatActivity去掉actionbar fullScreen

    网上已经有很多关于这个问题的解决方案,如果你试了都没有解决,那么请往下看.首先说下网上说的解决方案: 方案一:在AndroidManifest.xml中,为需要进行全屏显示的activity添加如下主 ...