英语的来历??

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了英语的来历??相关的知识,希望对你有一定的参考价值。

英伦三岛的第一批印欧居民是塞尔特人。原先岛上可能还有更早的居民,但是人烟稀少,所以没有留下多少遗迹。塞尔特人是古印欧人的一支,大约在四千五百年前离开他们在东欧的故乡向西迁移,在公元前一千年时,他们成了德国南部、阿尔卑斯山北麓的一个强大民族。在公元前五百年左右,他们开始向西迁移,后来到英语(English)是联合国的工作语言之一,也是事实上的国际交流语言。英语属于印欧语系中日耳曼语族下的西日耳曼语支,并通过英国的殖民活动传播到r界各地。由于在历史上曾和多种民族语言接触,它的词汇从一元变为多元,语法从“多屈折”变为“少屈折”,语音也发生了规律性的变化。根据以英语作为母语的人数计算,英语可能是世界上第三大语言,但它是世界上最广泛的第二语言。世界上60%以上的信件是用英语书写的,上两个世纪英国和美国在文化、经济、军事、政治和科学上的领先地位使得英语成为一种准国际语言。作用英语(English)世界通用语言,是联合国的工作语言之一,也是事实上的国际交流语言。英语属于印欧语系中耳曼语族下的西日耳曼语支,由古代从欧洲大陆移民大不列颠岛的盎格鲁、撒克逊和朱特部落的日耳曼人所说的语言演变而来,并通过英国的殖民活动传播到世界各地。由于在历史上曾和多种民族语言接触,它的词汇从一元变为多元,语法从“多曲折”变为“少曲折”,语音也发生了规律性的变化。根据以英语作为母语的人数计算,英语是世界上最广泛的第二语言,但它可能是世界上第二大或第四大语言(1999年统计为380,000,000人使用英语)。世界上60%以上的信件是用英语书写的,50%以上的报纸杂志是英语的。上两个世纪英国和美国在文化、经济、军事、政治和科学上的领先地位使得英语成为一种国际语言。英语也是与计算机联系最密切的语言,大多数编程语言都与英语有联系,而且随着互联网的使用,使英文的使用更普及。与英语最接近的无疑是弗里西语,这种语言现在仍然在荷兰北部弗里斯兰省中使用,大约有50万个使用者。一些人认为低地苏格兰语是与英语接近的一个独立语言,而一些人则认为它是英语的一个方言。苏格兰语、荷兰东部和德国北部的低地撒克逊语与英语也很接近。其他相关的语言包括荷兰语、南非荷兰语和德语。诺曼人于11世纪征服英国,带来大量法语词汇,很大程度地丰富了英语词汇
这样明白吗,其实你完全没必要知道英语的由来。
了英伦诸岛。这就是印欧人的第一次“入侵”。
参考技术A 你就算英国人它也未必说明白。
我问你汉语的由来,希望楼主给与解答
英伦三岛的第一批印欧居民是塞尔特人。原先岛上可能还有更早的居民,但是人烟稀少,所以没有留下多少遗迹。塞尔特人是古印欧人的一支,大约在四千五百年前离开他们在东欧的故乡向西迁移,在公元前一千年时,他们成了德国南部、阿尔卑斯山北麓的一个强大民族。在公元前五百年左右,他们开始向西迁移,后来到了英伦诸岛。这就是印欧人的第一次“入侵”。
英语(English)是联合国的工作语言之一,也是事实上的国际交流语言。英语属于印欧语系中日耳曼语族下的西日耳曼语支,并通过英国的殖民活动传播到r界各地。由于在历史上曾和多种民族语言接触,它的词汇从一元变为多元,语法从“多屈折”变为“少屈折”,语音也发生了规律性的变化。根据以英语作为母语的人数计算,英语可能是世界上第三大语言,但它是世界上最广泛的第二语言。世界上60%以上的信件是用英语书写的,上两个世纪英国和美国在文化、经济、军事、政治和科学上的领先地位使得英语成为一种准国际语言。作用英语(English)世界通用语言,是联合国的工作语言之一,也是事实上的国际交流语言。英语属于印欧语系中耳曼语族下的西日耳曼语支,由古代从欧洲大陆移民大不列颠岛的盎格鲁、撒克逊和朱特部落的日耳曼人所说的语言演变而来,并通过英国的殖民活动传播到世界各地。由于在历史上曾和多种民族语言接触,它的词汇从一元变为多元,语法从“多曲折”变为“少曲折”,语音也发生了规律性的变化。根据以英语作为母语的人数计算,英语是世界上最广泛的第二语言,但它可能是世界上第二大或第四大语言(1999年统计为380,000,000人使用英语)。世界上60%以上的信件是用英语书写的,50%以上的报纸杂志是英语的。上两个世纪英国和美国在文化、经济、军事、政治和科学上的领先地位使得英语成为一种国际语言。英语也是与计算机联系最密切的语言,大多数编程语言都与英语有联系,而且随着互联网的使用,使英文的使用更普及。与英语最接近的无疑是弗里西语,这种语言现在仍然在荷兰北部弗里斯兰省中使用,大约有50万个使用者。一些人认为低地苏格兰语是与英语接近的一个独立语言,而一些人则认为它是英语的一个方言。苏格兰语、荷兰东部和德国北部的低地撒克逊语与英语也很接近。其他相关的语言包括荷兰语、南非荷兰语和德语。诺曼人于11世纪征服英国,带来大量法语词汇,很大程度地丰富了英语词汇
这样明白吗,其实你完全没必要知道英语的由来。
参考技术B 英语历史
参看英语历史

早期日耳曼人部落(弗里西族、盎格鲁族、撒克逊族与朱特族)移民到英格兰,英语就是从他们的语言中变化继承下来。据《盎格鲁撒克逊编年史》记载,公元449年左右,不列颠群岛国王伏提庚(Vortigern)邀请“盎格鲁亲戚们”来帮助他对抗皮克特人。作为回报,他赐予盎格鲁族东南部的领土。随后他又进一步寻求支援,撒克逊族、盎格鲁族与朱特族人纷纷前来。《编年史》记载,最终这些“移民”建立了七个王国:诺森伯利亚、麦西亚、东盎格利亚、肯特、埃塞克斯、苏塞克斯、威塞克斯。

日尔曼人入侵后,统治了当地的凯尔特语民族,本地语言主要于苏格兰、威尔士、康沃尔与爱尔兰存活了下来。这些入侵者的语言逐渐形成了“古英语”,与近代弗里西语极为相象。English(英格兰人、英语)、England(英格兰)和East Anglia(东盎格利亚)这三个词是分别从描绘盎格鲁族的词汇发展而来:Englisc、 Angelcynn、Englaland。

1066年诺曼征服后三百年内,英格兰的国王只讲法语。因此一大批法语词汇进入了古英语,古英语本身也失去了大部分曲折变化,进化为中古英语。1500年左右的元音大推移将中古英语变形为近代英语。古英语最著名的文学作品是《贝奥武夫》,中古英语则是《坎特伯雷故事集》。

近代英语在莎士比亚所处的时期开始繁荣,一些学者将之分为早期近代英语与后期近代英语,分界线为1800年左右。随著不列颠对全世界大部分地区的占领和殖民,当地语言也很大程度上影响了英语的发展。

参考资料:http://zh.wikipedia.org/wiki/%E8%8B%B1%E8%AF%AD#.E8.8B.B1.E8.AA.9E.E5.8E.86.E5.8F.B2
参考技术C 英语简史(English Version)

A Brief Look at the History of English

The history of English is conventionally, if perhaps too neatly, divided into three periods usually called Old English (or Anglo-Saxon), Middle English, and Modern English. The earliest period begins with the migration of certain Germanic tribes from the continent to Britain in the fifth century A. D., though no records of their language survive from before the seventh century, and it continues until the end of the eleventh century or a bit later. By that time Latin, Old Norse (the language of the Viking invaders), and especially the Anglo-Norman French of the dominant class after the Norman Conquest in 1066 had begun to have a substantial impact on the lexicon, and the well-developed inflectional system that typifies the grammar of Old English had begun to break down. The following brief sample of Old English prose illustrates several of the significant ways in which change has so transformed English that we must look carefully to find points of resemblance between the language of the tenth century and our own. It is taken from Aelfric's "Homily on St. Gregory the Great" and concerns the famous story of how that pope came to send missionaries to convert the Anglo-Saxons to Christianity after seeing Anglo-Saxon boys for sale as slaves in Rome:

Eft he axode, hu ðære ðeode nama wære þe hi of comon. Him wæs geandwyrd, þæt hi Angle genemnode wæron. Þa cwæð he, "Rihtlice hi sind Angle gehatene, for ðan ðe hi engla wlite habbað, and swilcum gedafenað þæt hi on heofonum engla geferan beon."

A few of these words will be recognized as identical in spelling with their modern equivalents -- he, of, him, for, and, on -- and the resemblance of a few others to familiar words may be guessed -- nama to name, comon to come, wære to were, wæs to was -- but only those who have made a special study of Old English will be able to read the passage with understanding. The sense of it is as follows: "Again he [St. Gregory] asked what might be the name of the people from which they came. It was answered to him that they were named Angles. Then he said, 'Rightly are they called Angles because they have the beauty of angels, and it is fitting that such as they should be angels' companions in heaven.' " Some of the words in the original have survived in altered form, including axode (asked), hu (how), rihtlice (rightly), engla (angels), habbað (have), swilcum (such), heofonum (heaven), and beon (be). Others, however, have vanished from our lexicon, mostly without a trace, including several that were quite common words in Old English: eft "again," ðeode "people, nation," cwæð "said, spoke," gehatene "called, named," wlite "appearance, beauty," and geferan "companions." Recognition of some words is naturally hindered by the presence of two special characters, þ, called "thorn," and ð, called "edh," which served in Old English to represent the sounds now spelled with th.

Other points worth noting include the fact that the pronoun system did not yet, in the late tenth century, include the third person plural forms beginning with th-: hi appears where we would use they. Several aspects of word order will also strike the reader as oddly unlike ours. Subject and verb are inverted after an adverb -- þa cwæð he "Then said he" -- a phenomenon not unknown in Modern English but now restricted to a few adverbs such as never and requiring the presence of an auxiliary verb like do or have. In subordinate clauses the main verb must be last, and so an object or a preposition may precede it in a way no longer natural: þe hi of comon "which they from came," for ðan ðe hi engla wlite habbað "because they angels' beauty have."

Perhaps the most distinctive difference between Old and Modern English reflected in Aelfric's sentences is the elaborate system of inflections, of which we now have only remnants. Nouns, adjectives, and even the definite article are inflected for gender, case, and number: ðære ðeode "(of) the people" is feminine, genitive, and singular, Angle "Angles" is masculine, accusative, and plural, and swilcum "such" is masculine, dative, and plural. The system of inflections for verbs was also more elaborate than ours: for example, habbað "have" ends with the -að suffix characteristic of plural present indicative verbs. In addition, there were two imperative forms, four subjunctive forms (two for the present tense and two for the preterit, or past, tense), and several others which we no longer have. Even where Modern English retains a particular category of inflection, the form has often changed. Old English present participles ended in -ende not -ing, and past participles bore a prefix ge- (as geandwyrd "answered" above).

The period of Middle English extends roughly from the twelfth century through the fifteenth. The influence of French (and Latin, often by way of French) upon the lexicon continued throughout this period, the loss of some inflections and the reduction of others (often to a final unstressed vowel spelled -e) accelerated, and many changes took place within the phonological and grammatical systems of the language. A typical prose passage, especially one from the later part of the period, will not have such a foreign look to us as Aelfric's prose has; but it will not be mistaken for contemporary writing either. The following brief passage is drawn from a work of the late fourteenth century called Mandeville's Travels. It is fiction in the guise of travel literature, and, though it purports to be from the pen of an English knight, it was originally written in French and later translated into Latin and English. In this extract Mandeville describes the land of Bactria, apparently not an altogether inviting place, as it is inhabited by "full yuele [evil] folk and full cruell."

In þat lond ben trees þat beren wolle, as þogh it were of scheep; whereof men maken clothes, and all þing þat may ben made of wolle. In þat contree ben many ipotaynes, þat dwellen som tyme in the water, and somtyme on the lond: and þei ben half man and half hors, as I haue seyd before; and þei eten men, whan þei may take hem. And þere ben ryueres and watres þat ben fulle byttere, þree sithes more þan is the water of the see. In þat contré ben many griffounes, more plentee þan in ony other contree. Sum men seyn þat þei han the body vpward as an egle, and benethe as a lyoun: and treuly þei seyn soth þat þei ben of þat schapp. But o griffoun hath the body more gret, and is more strong, þanne eight lyouns, of suche lyouns as ben o this half; and more gret and strongere þan an hundred egles, suche as we han amonges vs. For o griffoun þere wil bere fleynge to his nest a gret hors, 3if he may fynde him at the poynt, or two oxen 3oked togidere, as þei gon at the plowgh.

The spelling is often peculiar by modern standards and even inconsistent within these few sentences (contré and contree, o [griffoun] and a [gret hors], þanne and þan, for example). Moreover, in the original text, there is in addition to thorn another old character 3, called "yogh," to make difficulty. It can represent several sounds but here may be thought of as equivalent to y. Even the older spellings (including those where u stands for v or vice versa) are recognizable, however, and there are only a few words like ipotaynes "hippopotamuses" and sithes "times" that have dropped out of the language altogether. We may notice a few words and phrases that have meanings no longer common such as byttere "salty," o this half "on this side of the world," and at the poynt "to hand," and the effect of the centuries-long dominance of French on the vocabulary is evident in many familiar words which could not have occurred in Aelfric's writing even if his subject had allowed them, words like contree, ryueres, plentee, egle, and lyoun.

In general word order is now very close to that of our time, though we notice constructions like hath the body more gret and three sithes more þan is the water of the see. We also notice that present tense verbs still receive a plural inflection as in beren, dwellen, han, and ben and that while nominative þei has replaced Aelfric's hi in the third person plural, the form for objects is still hem. All the same, the number of inflections for nouns, adjectives, and verbs has been greatly reduced, and in most respects Mandeville is closer to Modern than to Old English.

The period of Modern English extends from the sixteenth century to our own day. The early part of this period saw the completion of a revolution in the phonology of English that had begun in late Middle English and that effectively redistributed the occurrence of the vowel phonemes to something approximating their present pattern. (Mandeville's English would have sounded even less familiar to us than it looks.) Other important early developments include the stabilizing effect on spelling of the printing press and the beginning of the direct influence of Latin and, to a lesser extent, Greek on the lexicon. Later, as English came into contact with other cultures around the world and distinctive dialects of English developed in the many areas which Britain had colonized, numerous other languages made small but interesting contributions to our word-stock.

The historical aspect of English really encompasses more than the three stages of development just under consideration. English has what might be called a prehistory as well. As we have seen, our language did not simply spring into existence; it was brought from the Continent by Germanic tribes who had no form of writing and hence left no records. Philologists know that they must have spoken a dialect of a language that can be called West Germanic and that other dialects of this unknown language must have included the ancestors of such languages as German, Dutch, Low German, and Frisian. They know this because of certain systematic similarities which these languages share with each other but do not share with, say, Danish. However, they have had somehow to reconstruct what that language was like in its lexicon, phonology, grammar, and semantics as best they can through sophisticated techniques of comparison developed chiefly during the last century. Similarly, because ancient and modern languages like Old Norse and Gothic or Icelandic and Norwegian have points in common with Old English and Old High German or Dutch and English that they do not share with French or Russian, it is clear that there was an earlier unrecorded language that can be called simply Germanic and that must be reconstructed in the same way. Still earlier, Germanic was just a dialect (the ancestors of Greek, Latin, and Sanskrit were three other such dialects) of a language conventionally designated Indo-European, and thus English is just one relatively young member of an ancient family of languages whose descendants cover a fair portion of the globe.
http://www.iselong.com/english/0001/1124.htm
参考技术D bs
i.ennteuusdDr
ydi,sslb
lG
tdataDh
oes
ophtsooe
.iri
e
echniihehsgestee
.unsueiiyemt
i
Bfi
.aohdyi
,rhhseoscinWeS
wdlArn,
reem,mTn
lAwardhawtinepuoscacfo
,rcnseSngN
llali
t
dh
ea
enigadr1nid
le
plnytlt
itioansllkbadden
n
stgolnrws.clegmB
sctnaaerwrmrKgryeon
b.aecn
tgaraueSym
sayaeo
ie
l
e
Cesabo
nhtaat
e
sT
loieohreswCnnaorsmaisn
hhasb
s
A
hhicraoftArlerifl
ci
rxoannCftneendr.Os
i
f
hheoign.i.
tsow
agmoldgh
stlg
tl
l
naib
noEihea
Mkd,oldnned(oh,nuR
s
u
egaslaeb.d
r,
ne
ml
aa,
nirW,dalrnr
snt
nu.i,cthvheyerefn
gu
gl
na
tal
s
dh9e
uia
aferg
youuNndditdEneetgclnaidtel
ilemn
tyng
a
yd
dLcke,ltset,dInpoTtsVa
dT
itshg
d
i
)rlhafhvyawotrsvtweIghktfrdrate(
u
,d,lhaeny,he
taeaun
scesnnh
sohd,mlta
fn
so
eohkgudkdsiamunoeL
i
eshtav
dcef
v
i7ennhs,
a
unralidheni,tran
na
lrtwhe
o
fra(CEo
nr
nosaattadviheuslsx
ikornii
enatt
oec
msachhsttehwari
cxsrEyhtiiie
fFo
ioaty
m
l,m
moEit.cvDae
i
shweae
an
toaai
ln
ec
el
ehipgaonlLtt
rnuten
oi
r
irien
miDwvb
wt
ueeltoeiestB
t
gdeoriac
Iyh
ngwngntby
acldoh
n
oghtieTihnr
g
,aie,atsare
,fneJtinor
rihtecik
afaepTae
teg,nc
deirvr
)v
xw
de
lolisedoil
,vndrc
vrSbroentaa
dwia,,arlmol
rd
ers
tShrmoa
se
i
inuol
ns'n
e
o
E
sitkrwo
tgeinl
S
0.si
D
p
wd
dnl5r
pkpodre
a
plu.osaLwwieN
ehy,aagt
h
piwiheoogl
trdoantB
igimeytate
hT
mk)insaS
ul
rfoo.sieoem
m
hey(esd
en
i,
Ceseeareefelridnshcnd
nrk
sd
,it,tOb
tncivhogoe
rehgae
tinssso
spa
cEahngwftiieivt
e,MffetoAtc
n
plN
t
gewtgafmnphl
,at
lstnt,A
arch.,oaio
grlbr,nah,rte,srtiu
t.asaCknagassh
en
ndvreeve8lt
nr,erT
gifiinstetieogdna
oCt,ed
nnur
t
oaeCtt
Wnl
m
.srBrnm
tefkbacaa
iretOgu
nerD
ae
vs.hstA
n,
dyCgosaOiGBhh
renank
iitsuVerceceWr
aeeebr
grnTBeng
oohtaCthe
cado
k.agtd
swnSniem
a
tClnii
ieiesdkoieg
tem
h
i
ne
hntdmdhe
b,lyidnktewhavn,eagsle
e
:)tteer
rrsuTcs
raeTpu,ttya
eceaquh

:服务注册名称的来历

欢迎访问我的GitHub

关于服务注册名称

  • 服务注册名称,是指Eureka client注册到Eureka server时,用于标记自己身份的标志,举例说明,以下是个简单的Eureka client配置:
    server:
    port: 8082
    spring:
    application:
    name: springcloud-deep-provider
    eureka:
    client:
    serviceUrl:
      defaultZone: http://localhost:8081/eureka/
  • 这样配置的应用,启动后如果在Eureka server注册成功,那么Eureka server的home页面信息如下,红框中就是注册名称:

  • 本文目标是通过分析Eureka client源码来找出这个名称是如何创建的;

关于源码版本

  • 本次分析的Spring Cloud版本为Edgware.RELEASE,对应的eureka-client版本为1.7.0;

从启动说起

  1. 在spring-cloud-commons库的META-INF目录下有spring.factories文件,这是spring扩展规范的实现,这里面配置的类会被实例化,其中就包含了HostInfoEnvironmentPostProcessor这个类,如下图红框所示:
  2. HostInfoEnvironmentPostProcessor实现了EnvironmentPostProcessor接口,来看看官方文档对EnvironmentPostProcessor的描述:

    • 上图红框中说明开发者可以自定义环境变量;
    • 上图绿框中说明EnvironmentPostProcessor的实现类必须在spring.factories文件中定义;
    • 因此HostInfoEnvironmentPostProcessor类的作用已经清楚了:==自定义环境变量==;
  3. HostInfoEnvironmentPostProcessor源码如下:

    public class HostInfoEnvironmentPostProcessor
        implements EnvironmentPostProcessor, Ordered 
    
    // Before ConfigFileApplicationListener
    private int order = ConfigFileApplicationListener.DEFAULT_ORDER - 1;
    
    @Override
    public int getOrder() 
        return this.order;
    
    
    @Override
    public void postProcessEnvironment(ConfigurableEnvironment environment,
            SpringApplication application) 
        InetUtils.HostInfo hostInfo = getFirstNonLoopbackHostInfo(environment);
        LinkedHashMap<String, Object> map = new LinkedHashMap<>();
        map.put("spring.cloud.client.hostname", hostInfo.getHostname());
        map.put("spring.cloud.client.ipAddress", hostInfo.getIpAddress());
        MapPropertySource propertySource = new MapPropertySource(
                "springCloudClientHostInfo", map);
        environment.getPropertySources().addLast(propertySource);
    
    
    private HostInfo getFirstNonLoopbackHostInfo(ConfigurableEnvironment environment) 
        InetUtilsProperties target = new InetUtilsProperties();
        RelaxedDataBinder binder = new RelaxedDataBinder(target,
                InetUtilsProperties.PREFIX);
        binder.bind(new PropertySourcesPropertyValues(environment.getPropertySources()));
        try (InetUtils utils = new InetUtils(target)) 
            return utils.findFirstNonLoopbackHostInfo();
        
    
    
    • 上述代码有两处需要注意:
      第一,设置了两个环境变量:==spring.cloud.client.hostname==和==spring.cloud.client.ipAddress==;
      第二,getFirstNonLoopbackHostInfo方法返回的对象中,127.0.0.1这样的IP地址是会被过滤掉的,过滤逻辑很简单,源码在Inet4Address类的isLoopbackAddress方法:
      public boolean isLoopbackAddress() 
      /* 127.x.x.x */
      byte[] byteAddr = getAddress();
      return byteAddr[0] == 127;
      

      小结:HostInfoEnvironmentPostProcessor的作用是把本机的hostname和IP地址设置到环境变量中;

在配置类中保存服务名称

  1. 接下来看看配置类EurekaClientAutoConfiguration,这里面主要是和Eureka相关的配置信息的数据和逻辑;
  2. 请看方法eurekaInstanceConfigBean,该方法向Spring容器环境提供EurekaInstanceConfigBean实例,注意==instance.setInstanceId(getDefaultInstanceId(propertyResolver))==这一行:

    @Bean
    @ConditionalOnMissingBean(value = EurekaInstanceConfig.class, search = SearchStrategy.CURRENT)
    public EurekaInstanceConfigBean eurekaInstanceConfigBean(InetUtils inetUtils,
                                                             ManagementMetadataProvider managementMetadataProvider) throws MalformedURLException 
        PropertyResolver eurekaPropertyResolver = new RelaxedPropertyResolver(this.env, "eureka.instance.");
        String hostname = eurekaPropertyResolver.getProperty("hostname");
    
        boolean preferIpAddress = Boolean.parseBoolean(eurekaPropertyResolver.getProperty("preferIpAddress"));
        boolean isSecurePortEnabled = Boolean.parseBoolean(eurekaPropertyResolver.getProperty("securePortEnabled"));
        String serverContextPath = propertyResolver.getProperty("server.contextPath", "/");
        int serverPort = Integer.valueOf(propertyResolver.getProperty("server.port", propertyResolver.getProperty("port", "8080")));
    
        Integer managementPort = propertyResolver.getProperty("management.port", Integer.class);// nullable. should be wrapped into optional
        String managementContextPath = propertyResolver.getProperty("management.contextPath");// nullable. should be wrapped into optional
        Integer jmxPort = propertyResolver.getProperty("com.sun.management.jmxremote.port", Integer.class);//nullable
        EurekaInstanceConfigBean instance = new EurekaInstanceConfigBean(inetUtils);
    
        instance.setNonSecurePort(serverPort);
        //服务自身的名称在此设置,保存到instance后,其他地方就可以使用了
        instance.setInstanceId(getDefaultInstanceId(propertyResolver));
  3. 顺藤摸瓜,展开方法getDefaultInstanceId:

    public static String getDefaultInstanceId(PropertyResolver resolver) 
        RelaxedPropertyResolver relaxed = new RelaxedPropertyResolver(resolver);
        String vcapInstanceId = relaxed.getProperty("vcap.application.instance_id");
        if (StringUtils.hasText(vcapInstanceId)) 
            return vcapInstanceId;
        
    
        String hostname = relaxed.getProperty("spring.cloud.client.hostname");
        String appName = relaxed.getProperty("spring.application.name");
    
        String namePart = combineParts(hostname, SEPARATOR, appName);
    
        String indexPart = relaxed.getProperty("spring.application.instance_id",
                relaxed.getProperty("server.port"));
    
        return combineParts(namePart, SEPARATOR, indexPart);
    
    • 如上述代码所示,真相大白,服务注册名称一共有三部分:hostname、应用名称、自定义实例ID,如果自定义实例ID没有配置就用监听端口代替;
  • 此时再来回顾之前在Eureka server的home页面上看到的服务注册名:localhost:springcloud-deep-provider:8082,果然与源码一致;
    1. 源码读到此处,禁不住手痒,按照上面的逻辑,在应用的aplication.yml中增加配置项==spring.application.instance_id==,看看能否生效,改过的aplication.yml内容如下图所示,红框中是新增的自定义实例ID配置:
    2. 重启应用,重新注册到Eureka server,此时再看home页面如下图红框,服务注册名称果然已经更新:

使用配置类中的服务名称

  • 现在我们知道了EurekaInstanceConfigBean实例的instanceId字段被设置为"hostname:应用名称:自定义实例ID",接下来看该字段如何被提交到Eureka server;
  1. 在EurekaClientAutoConfiguration类中有个eurekaApplicationInfoManager方法,为spring容器提供了ApplicationInfoManager实例:

    @Bean
    @ConditionalOnMissingBean(value = ApplicationInfoManager.class, search = SearchStrategy.CURRENT)
    public ApplicationInfoManager eurekaApplicationInfoManager(
        EurekaInstanceConfig config) 
        //config就是前面看到的EurekaInstanceConfigBean实例,
        //EurekaInstanceConfig是个接口,EurekaInstanceConfigBean是该接口的实现,
        //instanceInfo实例中已经保存了EurekaInstanceConfigBean的信息,也包括instanceId字段
        InstanceInfo instanceInfo = new InstanceInfoFactory().create(config);
        //生成ApplicationInfoManager实例,
        //config和instanceInfo都被设置为ApplicationInfoManager实例的成员变量
        return new ApplicationInfoManager(config, instanceInfo);
    

    如上所示,spring容器中有了ApplicationInfoManager实例,就可以通过该实例获得服务注册名称;

  2. Eureka client向Eureka server发起服务注册的操作是在DiscoveryClient类中进行的,该类的构造方法如下:

如上图所示,红框中ApplicationInfoManager实例被注入,蓝框中表明DiscoveryClient的成员变量instanceInfo获得了InstanceInfo实例;

  1. 具体的注册逻辑在DiscoveryClient的register方法中,可见成员变量instanceInfo被当作入参传入了注册逻辑的API:
    /**
     * Register with the eureka service by making the appropriate REST call.
     */
    boolean register() throws Throwable 
        logger.info(PREFIX + appPathIdentifier + ": registering service...");
        EurekaHttpResponse<Void> httpResponse;
        try 
            //以成员变量instanceInfo作为入参进行注册
            httpResponse = eurekaTransport.registrationClient.register(instanceInfo);
         catch (Exception e) 
            logger.warn(" - registration failed ", PREFIX + appPathIdentifier, e.getMessage(), e);
            throw e;
        
        if (logger.isInfoEnabled()) 
            logger.info(" - registration status: ", PREFIX + appPathIdentifier, httpResponse.getStatusCode());
        
        return httpResponse.getStatusCode() == 204;
    
  2. 上述代码中的==eurekaTransport.registrationClient.register(instanceInfo)==方法,经过层层调用,最终调用了AbstractJerseyEurekaHttpClient类的register方法,如下图所示:
  • 上图的红框表明,POST请求时InstanceInfo实例被作为请求参数提交到了Eureka server;

Wireshark抓包验证

  • 至此,代码分析已经结束了,最后我们用Wireshark抓包来验证之前的分析结果,在Eureka client所在电脑上用Wireshark2.6.3来分析注册请求:

  • 如上图所示,红框中就是注册请求,绿框中是请求包头的全部内容,也就是前面看到的InstanceInfo实例的内容,蓝框中的内容,就是服务注册名称的键值对,值就是Eureka server收到的注册名称;

  • 最后来小结一下,服务注册名称从诞生到提交至Eureka server的过程:
    1. HostInfoEnvironmentPostProcessor将本机的hostname和IP地址设置到应用环境变量中;
    2. 配置类EurekaClientAutoConfiguration中,创建一个EurekaInstanceConfigBean类型的bean,其instanceId字段就是即将上报到Eureka server的自身名称,instanceId字段的内容由hostname、应用名称、自定义实例ID拼接而成,其中自定义实例ID来自配置项"spring.application.instance_id",如果不存在就用服务监听端口代替;
    3. ApplicationInfoManager类型的bean在创建时被注入EurekaInstanceConfigBean实例,用于创建ApplicationInfoManager的成员变量instanceInfo;
    4. DiscoveryClient的构造方法中注入了ApplicationInfoManager,于是DiscoveryClient的成员变量instanceInfo就被赋值为ApplicationInfoManager的成员变量instanceInfo;
    5. DiscoveryClient的register方法负责注册到Eureka server的逻辑,用到的参数就是成员变量instanceInfo;
    6. 发起注册网络请求的操作最终由AbstractJerseyEurekaHttpClient类的register方法完成,POST的内容就是instanceInfo实例;

欢迎关注51CTO博客:程序员欣宸

以上是关于英语的来历??的主要内容,如果未能解决你的问题,请参考以下文章

春节由来及元宵节的由来(英文)

像黄瓜一样冷静

英式英语和美式英语的单词一样吗

英式英语和美式英语有啥区别?

如何区别英式英语和美式英语?

急求关于成功职业英语的200字英语作文!!