很多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,进行依赖控制,当然也可以这样,将他们分开,进行单独项目进行配置,那么可以单独建立,一个就不能拿到公司的所有的项目

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.</modelVersion>
<packaging>pom</packaging>
<modules>
<module>springrurekaserver</module>
</modules>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1..RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.cxy</groupId>
<artifactId>springcloudlearning</artifactId>
<version>0.0.-SNAPSHOT</version>
<name>springcloudlearning</name>
<description>Demo project for Spring Boot</description> <properties>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.SR3</spring-cloud.version>
</properties> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
</dependencies> <dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build> <!--<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</repository>
</repositories>--> </project>
    <!--<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</repository>
</repositories>-->

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

然后参照官方:

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

然后再创建application。yml

server:
port: eureka:
instance:
hostname: localhost
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://127.0.0.1:8761/eureka/

然后再创建

package com.cxy;

import org.springframework.boot.Banner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringBootVersion;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; @SpringBootApplication
@EnableEurekaServer
public class EurekaApplication {
public static void main(String[] args) {
new SpringApplicationBuilder(EurekaApplication.class)
// .web(WebApplicationType.SERVLET)
.main(SpringBootVersion.class)
.run(args);
/*
SpringApplicationBuilder springApplicationBuilder = new SpringApplicationBuilder(EnableEurekaServer.class);
SpringApplicationBuilder web = springApplicationBuilder.web(webappl);
web.run(args);
*/ SpringApplication.run(EurekaApplication.class,args);
}
}

可以看下官方:

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

传入了一个webApplicationType

这个是什么东西呢:

/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ package org.springframework.boot; import org.springframework.util.ClassUtils; /**
* An enumeration of possible types of web application.
*
* @author Andy Wilkinson
* @author Brian Clozel
* @since 2.0.0
*/
public enum WebApplicationType { /**
* The application should not run as a web application and should not start an
* embedded web server.
*/
NONE, /**
* The application should run as a servlet-based web application and should start an
* embedded servlet web server.
*/
SERVLET, /**
* The application should run as a reactive web application and should start an
* embedded reactive web server.
*/
REACTIVE; private static final String[] SERVLET_INDICATOR_CLASSES = { "javax.servlet.Servlet",
"org.springframework.web.context.ConfigurableWebApplicationContext" }; private static final String WEBMVC_INDICATOR_CLASS = "org.springframework." + "web.servlet.DispatcherServlet"; private static final String WEBFLUX_INDICATOR_CLASS = "org." + "springframework.web.reactive.DispatcherHandler"; private static final String JERSEY_INDICATOR_CLASS = "org.glassfish.jersey.servlet.ServletContainer"; private static final String SERVLET_APPLICATION_CONTEXT_CLASS = "org.springframework.web.context.WebApplicationContext"; private static final String REACTIVE_APPLICATION_CONTEXT_CLASS = "org.springframework.boot.web.reactive.context.ReactiveWebApplicationContext"; static WebApplicationType deduceFromClasspath() {
if (ClassUtils.isPresent(WEBFLUX_INDICATOR_CLASS, null) && !ClassUtils.isPresent(WEBMVC_INDICATOR_CLASS, null)
&& !ClassUtils.isPresent(JERSEY_INDICATOR_CLASS, null)) {
return WebApplicationType.REACTIVE;
}
for (String className : SERVLET_INDICATOR_CLASSES) {
if (!ClassUtils.isPresent(className, null)) {
return WebApplicationType.NONE;
}
}
return WebApplicationType.SERVLET;
} static WebApplicationType deduceFromApplicationContext(Class<?> applicationContextClass) {
if (isAssignable(SERVLET_APPLICATION_CONTEXT_CLASS, applicationContextClass)) {
return WebApplicationType.SERVLET;
}
if (isAssignable(REACTIVE_APPLICATION_CONTEXT_CLASS, applicationContextClass)) {
return WebApplicationType.REACTIVE;
}
return WebApplicationType.NONE;
} private static boolean isAssignable(String target, Class<?> type) {
try {
return ClassUtils.resolveClassName(target, null).isAssignableFrom(type);
}
catch (Throwable ex) {
return false;
}
} }

枚举类,所以看下注释:

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

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

例如:

官方启动会构建很多东西,可以加载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. docker x509: certificate has expired or is not yet valid

    系统环境:centos 6.5 内核版本:2.6.32-696.1.1.el6.x86_64 程序版本:Docker version 1.7.1, build 786b29d/1.7.1 问题:下载镜 ...

  2. 微信公众号开发笔记-验证token

    开发 话不多说我们直接进入主题 我们先去微信公众号申请一个公众号: 申请完成之后我们找到开发下的基本配置 然后找到进行基本配置,我们需要一个url地址来验证,这里的地址必需要是外网,Token是我们任 ...

  3. python基础【第十篇】

    Python文件操作 1.常规格式 f = open(file="文件所在路径/文件名",mode="操作模式",encoding="选择的编码&qu ...

  4. html - body标签中相关标签

    body标签中相关标签   今日内容: 字体标签: h1~h6.<font>.<u>.<b>.<strong><em>.<sup> ...

  5. python- 属性 静态方法,类方法

    一,面向对象结构与成员 1,1 面向对象结构分析: 那么每个大区域又可以分为多个小部分: class A: company_name = '老男孩教育' # 静态变量(静态字段) __iphone = ...

  6. 《linux 内核全然剖析》sched.c sched.h 代码分析笔记

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/u011368821/article/details/25129835 sched.c sched.h ...

  7. 【LeetCode】水题(刚开始重新刷题找感觉用的)

    [9] Palindrome Number [Easy] 给一个数字,用不转化成字符串的方式判断它是否是回文. 先求数字长度,然后把数字的后半段做翻转(就是不断地取模,除10这种方式),然后判断前后半 ...

  8. mac上安装mamp集成环境

    深知mac配置环境是个坑,本人之前用的是xampp因为近期需要mongodb扩展,死活装不明白,索性就换了一个集成环境,在网上找了好多,最后选择了mamp 因为正版的要收费,所以在下载了N个以后终于找 ...

  9. php高版本安装ecshop错误解决方法

    1.Strict Standards: Non-static method cls_image::gd_version() should not be called statically in F:\ ...

  10. 【转】SpringMVC整合websocket实现消息推送及触发

    1.创建websocket握手协议的后台 (1)HandShake的实现类 /** *Project Name: price *File Name:    HandShake.java *Packag ...