├── LICENSE
├── README.md
├── database
└── README.md
├── distributed system
└── README.md
├── framework
└── README.md
└── img
├── MySQL命令行查看版本号.jpg
├── README.md
├── Solr.png
├── Spring Framework.jpg
├── Spring组件.png
├── status查看版本号.jpg
└── 系统函数查看版本号.jpg
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # 关于
2 |
3 | - 本仓库将以面试题为导向,将 Java 后台开发面试中遇到的问题和解题思路或答案整理输出,一方面是为了方便自己复盘,另一方面也是希望对其他胖友能有所帮助;
4 | - 由于水平有限,本仓库中部分题目来源于面试所遇,一部分源于网上;
5 | - 面试题只是为了让我们在学习这些技术的时候知道如何抓住重点,但不能只浮于表面,而是要稳扎稳打,把基础打牢,勿在浮沙筑高台;
6 | - 源码之中,了无秘密,即使现在没有太多源码阅读的经验,后续也一定要多多阅读源码。
7 | - TODO:后续会依次整理部分题目的参考解答思路,整理的目的是为了后续更深入地学习一个技术,而不是让大家背答案!
8 |
9 | # 前言
10 |
11 | - 整理不易,如果觉得有帮助请点个 `star`
12 |
13 | # 目录
14 |
15 | ## Java基础
16 | ## Java并发
17 | ## JVM
18 | ## 框架
19 | - [Spring](https://github.com/bigrotor187/awesome-java-interview/tree/master/framework#spring)
20 | - [Spring Framework](https://github.com/bigrotor187/awesome-java-interview/tree/master/framework#spring-framework)
21 | - [Spring Bean](https://github.com/bigrotor187/awesome-java-interview/tree/master/framework#spring-bean)
22 | - [Spring IoC](https://github.com/bigrotor187/awesome-java-interview/tree/master/framework#spring-ioc)
23 | - [Spring 注解](https://github.com/bigrotor187/awesome-java-interview/tree/master/framework#spring-%E6%B3%A8%E8%A7%A3)
24 | - [Spring AOP](https://github.com/bigrotor187/awesome-java-interview/tree/master/framework#spring-aop)
25 | - [Spring 事务](https://github.com/bigrotor187/awesome-java-interview/tree/master/framework#spring-%E4%BA%8B%E5%8A%A1)
26 | - [SpringMVC](https://github.com/bigrotor187/awesome-java-interview/tree/master/framework#springmvc)
27 | - [Mybatis](https://github.com/bigrotor187/awesome-java-interview/tree/master/framework#mybatis)
28 | - [SpringBoot](https://github.com/bigrotor187/awesome-java-interview/tree/master/framework#springboot)
29 | - [Hibernate](https://github.com/bigrotor187/awesome-java-interview/tree/master/framework#hibernate)
30 | ## 分布式系统
31 | ### 分布式缓存
32 | - Memcached
33 | - [Redis](https://github.com/bigrotor187/awesome-java-interview/tree/master/distributed%20system#redis)
34 |
35 | ### 分布式服务框架
36 | - Dubbo
37 |
38 | ### 分布式协调服务
39 | - Zookeeper
40 |
41 | ### 分布式消息队列
42 | - RabbitMQ
43 | - Kafka
44 |
45 | ### 分布式搜索引擎
46 |
47 | - [Elasticsearch](https://github.com/bigrotor187/awesome-java-interview/tree/master/distributed%20system#elasticsearch)
48 | - [Solr](https://github.com/bigrotor187/awesome-java-interview/tree/master/distributed%20system#solr)
49 |
50 | ### 分布式事务
51 |
52 | ## 数据库
53 | - [MySQL](https://github.com/bigrotor187/awesome-java-interview/tree/master/database#mysql)
54 |
55 | ## 设计模式
56 | ## 数据结构和算法
57 | - 详见[链接](https://github.com/bigrotor187/awesome-java-notes#%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E4%B8%8E%E7%AE%97%E6%B3%95)
58 |
--------------------------------------------------------------------------------
/database/README.md:
--------------------------------------------------------------------------------
1 | # MySQL 学习笔记
2 |
3 | ## 《MySQL是怎样运行的——从根儿上理解MySQL》
4 |
5 | - [1、MySQL 概述]()
6 | - [2、MySQL 查询请求执行过程]()
7 | - [3、常用存储引擎]()
8 | - [4、字符集和比较规则]()
9 | - [5、InnoDB 是如何存储一条数据记录的?]()
10 | - [6、InnoDB 数据页结构]()
11 | - [7、快速查询的秘籍——B+ 树索引简介]()
12 | - [8、B+ 树索引是如何使用的?]()
13 | - [9、MySQL 的数据目录]()
14 | - [10、存放页面的大池子——InnoDB 的表空间]()
15 | - [11、MySQL 单表是如何访问的?]()
16 | - [12、连接的原理及查询成本的优化]()
17 | - [13、MySQL 基于规则的优化与子查询优化]()
18 | - [14、EXPLAIN 详解]()
19 | - [15、InnoDB 的 Buffer Pool——条件磁盘和 CPU 的矛盾]()
20 | - [16、MySQL 事务简介]()
21 | - [17、redo 日志]()
22 | - [18、undo 日志]()
23 | - [19、事务隔离级别和 MVCC]()
24 | - [20、面试老大难——锁]()
25 |
26 |
27 | # MySQL 实战案例
28 | - [1、MySQL 加锁分析](http://www.fanyilun.me/2017/04/20/MySQL%E5%8A%A0%E9%94%81%E5%88%86%E6%9E%90/)
29 | - [2、常见 MySQL 死锁案例](https://github.com/aneasystone/mysql-deadlocks)
30 |
31 |
32 | # MySQL 面试问题
33 |
34 | - [1、数据库的三范式是什么?](https://github.com/bigrotor187/awesome-java-interview/tree/master/database#1%E6%95%B0%E6%8D%AE%E5%BA%93%E7%9A%84%E4%B8%89%E8%8C%83%E5%BC%8F%E6%98%AF%E4%BB%80%E4%B9%88)
35 | - [2、一张自增表里面总共有 7 条数据,删除了最后 2 条数据,重启 mysql 数据库,又插入了一条数据,此时 id 是几?](https://github.com/bigrotor187/awesome-java-interview/tree/master/database#2%E4%B8%80%E5%BC%A0%E8%87%AA%E5%A2%9E%E8%A1%A8%E9%87%8C%E9%9D%A2%E6%80%BB%E5%85%B1%E6%9C%89-7-%E6%9D%A1%E6%95%B0%E6%8D%AE%E5%88%A0%E9%99%A4%E4%BA%86%E6%9C%80%E5%90%8E-2-%E6%9D%A1%E6%95%B0%E6%8D%AE%E9%87%8D%E5%90%AF-mysql-%E6%95%B0%E6%8D%AE%E5%BA%93%E5%8F%88%E6%8F%92%E5%85%A5%E4%BA%86%E4%B8%80%E6%9D%A1%E6%95%B0%E6%8D%AE%E6%AD%A4%E6%97%B6-id-%E6%98%AF%E5%87%A0)
36 | - [3、如何获取当前数据库版本?](https://github.com/bigrotor187/awesome-java-interview/tree/master/database#3%E5%A6%82%E4%BD%95%E8%8E%B7%E5%8F%96%E5%BD%93%E5%89%8D%E6%95%B0%E6%8D%AE%E5%BA%93%E7%89%88%E6%9C%AC)
37 | - [4、说一下 ACID 是什么?](https://github.com/bigrotor187/awesome-java-interview/tree/master/database#4%E8%AF%B4%E4%B8%80%E4%B8%8B-acid-%E6%98%AF%E4%BB%80%E4%B9%88)
38 | - [5、char 和 varchar 的区别是什么?](https://github.com/bigrotor187/awesome-java-interview/tree/master/database#5char-%E5%92%8C-varchar-%E7%9A%84%E5%8C%BA%E5%88%AB%E6%98%AF%E4%BB%80%E4%B9%88)
39 | - [6、float 和 double 的区别是什么?](https://github.com/bigrotor187/awesome-java-interview/tree/master/database#6float-%E5%92%8C-double-%E7%9A%84%E5%8C%BA%E5%88%AB%E6%98%AF%E4%BB%80%E4%B9%88)
40 | - [7、mysql 的内连接、左连接、右连接有什么区别?](https://github.com/bigrotor187/awesome-java-interview/tree/master/database#7mysql-%E7%9A%84%E5%86%85%E8%BF%9E%E6%8E%A5%E5%B7%A6%E8%BF%9E%E6%8E%A5%E5%8F%B3%E8%BF%9E%E6%8E%A5%E6%9C%89%E4%BB%80%E4%B9%88%E5%8C%BA%E5%88%AB)
41 | - [8、mysql 索引是怎么实现的?](https://github.com/bigrotor187/awesome-java-interview/tree/master/database#8mysql-%E7%B4%A2%E5%BC%95%E6%98%AF%E6%80%8E%E4%B9%88%E5%AE%9E%E7%8E%B0%E7%9A%84)
42 | - [9、怎么验证 mysql 的索引是否满足需求?](https://github.com/bigrotor187/awesome-java-interview/tree/master/database#9%E6%80%8E%E4%B9%88%E9%AA%8C%E8%AF%81-mysql-%E7%9A%84%E7%B4%A2%E5%BC%95%E6%98%AF%E5%90%A6%E6%BB%A1%E8%B6%B3%E9%9C%80%E6%B1%82)
43 | - [10、说一下数据库的事务隔离?](https://github.com/bigrotor187/awesome-java-interview/tree/master/database#10%E8%AF%B4%E4%B8%80%E4%B8%8B%E6%95%B0%E6%8D%AE%E5%BA%93%E7%9A%84%E4%BA%8B%E5%8A%A1%E9%9A%94%E7%A6%BB)
44 | - [11、说一下 mysql 常用的引擎?](https://github.com/bigrotor187/awesome-java-interview/tree/master/database#11%E8%AF%B4%E4%B8%80%E4%B8%8B-mysql-%E5%B8%B8%E7%94%A8%E7%9A%84%E5%BC%95%E6%93%8E)
45 | - [12、说一下 mysql 的行锁和表锁?](https://github.com/bigrotor187/awesome-java-interview/tree/master/database#12%E8%AF%B4%E4%B8%80%E4%B8%8B-mysql-%E7%9A%84%E8%A1%8C%E9%94%81%E5%92%8C%E8%A1%A8%E9%94%81)
46 | - [13、说一下乐观锁和悲观锁?](https://github.com/bigrotor187/awesome-java-interview/tree/master/database#13%E8%AF%B4%E4%B8%80%E4%B8%8B%E4%B9%90%E8%A7%82%E9%94%81%E5%92%8C%E6%82%B2%E8%A7%82%E9%94%81)
47 | - [14、mysql 问题排查都有哪些手段?](https://github.com/bigrotor187/awesome-java-interview/tree/master/database#14mysql-%E9%97%AE%E9%A2%98%E6%8E%92%E6%9F%A5%E9%83%BD%E6%9C%89%E5%93%AA%E4%BA%9B%E6%89%8B%E6%AE%B5)
48 | - [15、如何做 mysql 的性能优化?](https://github.com/bigrotor187/awesome-java-interview/tree/master/database#15%E5%A6%82%E4%BD%95%E5%81%9A-mysql-%E7%9A%84%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96)
49 |
50 | ## 1、数据库的三范式是什么?
51 | - **第一范式:** 每个列都不可以再拆分。
52 |
53 | - **第二范式:** 非主键列完全依赖于主键,而不能是依赖于主键的一部分.。
54 |
55 | - **第三范式:** 非主键列只依赖于主键,不依赖于其他非主键。
56 |
57 | 在设计数据库结构的时候,要尽量遵守三范式,如果不遵守,必须有足够的理由,比如性能。事实上我们经常会为了性能而妥协数据库的设计。
58 |
59 | ## 2、一张自增表里面总共有 7 条数据,删除了最后 2 条数据,重启 mysql 数据库,又插入了一条数据,此时 id 是几?
60 | - 一般情况下,MySQL 中创建表的类型为 InnoDB,如果新增一条记录(在 MySQL 不重启的情况下),这条记录的 ID 为 8;但是,如果**重启 MySQL 的情况下**,那么这条记录的 ID 为
61 | 6,因为 InnoDB 表只把自增主键的最大 ID 记录到内存中,所以重启数据库或者对表执行 OPTIMIZE 操作,都会使最大 ID 丢失。
62 | - 如果我们设置表的类型是 MyISAM,那么这条记录的 ID 就是 8。因为MylSAM表会把自增主键的最大ID记录到数据文件里面,重启MYSQL后,自增主键的最大ID也不会丢失。
63 | - 如果在这 7 条记录里面删除的是中间的几个记录(比如删除的是 3,4,5 三条记录),重启 MySQL 数据库后,insert 一条记录后,ID 都是 8。因为内存或者数据库文件存储的都是自增主键的最大 ID。
64 |
65 | ## 3、如何获取当前数据库版本?
66 | - 一、使用命令行模式进入mysql会看到最开始的提示符:
67 |
68 | 
69 |
70 | - 二、命令行中使用 status 可以查看:
71 |
72 | 
73 |
74 | - 三、使用系统函数 version():
75 |
76 | 
77 |
78 | ## 4、说一下 ACID 是什么?
79 |
80 | - ACID 指的是事务 的四大特性,分别是`原子性(Atomicity)`、`一致性(Consistency)`、`隔离性(Isolation)`、`永久性(Durability)`。
81 | - **原子性:** 原子性是指事务是一个不可分割的工作单位,事务中的操作要么全部成功,要么全部失败。比如在同一个事务中的SQL语句,要么全部执行成功,要么全部执行失败。
82 | - **一致性:** 官网上事务一致性的概念是:事务必须使数据库从一个一致性状态变换到另外一个一致性状态。以转账为例子,A向B转账,假设转账之前这两个用户的钱加起来总共是2000,那么A向B转账之后,不管这两个账户怎么转,A用户的钱和B用户的钱加起来的总额还是2000,这个就是事务的一致性。
83 | - **隔离性:** 事务的隔离性是多个用户并发访问数据库时,数据库为每一个用户开启的事务,不能被其他事务的操作数据所干扰,多个并发事务之间要相互隔离。
84 | - **永久性:** 持久性是指一个事务一旦被提交,它对数据库中数据的改变就是永久性的,接下来即使数据库发生故障也不应该对其有任何影响。
85 |
86 | ## 5、char 和 varchar 的区别是什么?
87 |
88 | - **是否是定长的:** char 是一个定长字段,假如申请了char(10) 的空间,那么无论实际存储多少内容,该字段都占用 10 个字符。而 varchar 是变长的,也就是说申请的只是最大长度,占用的空间为实际字符长度 +1,最后一个字符存储使用了多长的空间。
89 |
90 | - **从检索效率上来讲**,char > varchar,因此在使用中如果确定某个字段的值的长度,可以使用 char,否则应该尽量使用 varchar。例如存储用户MD5加密后的密码,则应该使用 char。
91 |
92 | ## 6、float 和 double 的区别是什么?
93 |
94 | - float类型表示单精度浮点数值,double类型表示双精度浮点数值,float和double都是浮点型,而decimal是定点型;
95 | - MySQL 浮点型和定点型可以用类型名称后加(M,D)来表示,M表示该值的总共长度,D表示小数点后面的长度,M和D又称为精度和标度,如float(5,2)的 可显示为999.99,MySQL保存值时会进行四舍五入,如果插入999.009,则结果为999.01。
96 | - float和double在不指定精度时,默认会按照实际的精度来显示,而DECIMAL在不指定精度时,默认整数为10,小数为0。
97 |
98 | > 具体可参考:https://blog.csdn.net/lihua5419/article/details/81316914
99 |
100 | ## 7、MySQL 的内连接、左连接、右连接有什么区别?
101 |
102 | - 左连接:左边有的,右边没有的为 null
103 |
104 | - 右连接:左边没有的,右边有的为 null
105 |
106 | - 内连接:显示左边右边共有的
107 |
108 | > 具体请移步: https://blog.csdn.net/wang0112233/article/details/78418698
109 |
110 | ## 8、MySQL 索引是如何实现的?
111 |
112 | - 索引的数据结构和具体的数据库存储引擎的实现有关,在 MySQL 中使用较多的索引有哈希索引、BTree索引等。其中,哈希索引底层数据结构使用的是哈希表,而BTree索引使用的是B树中的B+Tree。在 MySQL 中,经常使用的 InnoDB 存储引擎的默认索引实现为:BTree索引。
113 | - 创建索引时,建议对如下情况创建:
114 | - 出现在 SELECT、UPDATE、DELETE 语句的 WHERE 从句中的列
115 | - 包含在 ORDER BY、GROUP BY、DISTINCT 中的字段
116 | - 并不要将符合 1 和 2 中的字段的列都建立一个索引, 通常将 1、2 中的字段建立联合索引效果更好
117 | - 多表 join 的关联列
118 |
119 | 常见的索引类型有:主键索引、唯一索引、普通索引、全文索引、组合索引
120 |
121 | 1、主键索引:即主索引,根据主键pk_clolum(length)建立索引,不允许重复,不允许空值;
122 | `ALTER TABLE `table_name` ADD PRIMARY KEY (`column`);`
123 |
124 | 2、唯一索引:用来建立索引的列的值必须是唯一的,允许空值
125 | `ALTER TABLE `table_name` ADD UNIQUE (`column`) ;`
126 |
127 | 3、普通索引:用表中的普通列构建的索引,没有任何限制
128 | `ALTER TABLE `table_name` ADD INDEX index_name (`column`);`
129 |
130 | 4、全文索引:用大文本对象的列构建的索引
131 | `ALTER TABLE `table_name` ADD FULLTEXT (`column`);`
132 |
133 | 5、组合索引:用多个列组合构建的索引,这多个列中的值不允许有空值
134 | `ALTER TABLE `table_name` ADD INDEX index_name (`column1`, `column2`, `column3`);`
135 |
136 | ## 9、怎么验证 MySQL 的索引是否满足需求?或者换个说法,如何判断创建的索引有没有被使用到?或者说怎么才可以知道这条语句运行很慢的原因?
137 |
138 | 需要根据查询需求来决定配置索引的类型,一旦确定索引类型之后,可以使用 EXPLAIN 查看 SQL 执行计划,确认索引是否满足需求。
139 |
140 | - MySQL提供了 EXPLAIN 命令来查看语句的执行计划,MySQL在执行某个语句之前,会将该语句过一遍查询优化器,之后会拿到对语句的分析,也就是执行计划,其中包含了许多信息。可以通过其中和索引有关的信息来分析是否命中了索引,例如 possilbe_key,key,key_len 等字段,分别说明了此语句可能会使用的索引,实际使用的索引以及使用的索引长度。具体过程如下:
141 |
142 | - 在 select 语句前加上 explain 就可以用来查看 sql 的执行计划,EXPLAIN 显示了 MySQL 如何使用索引来处理 select 语句以及连接表;
143 |
144 | - possible_keys:显示可能应用在这张表中的索引。如果为空,没有可能的索引。可以为相关的域从WHERE语句中选择一个合适的语句
145 |
146 | - key: 实际使用的索引。如果为 NULL,则没有使用索引。很少的情况下,MySQL 会选择优化不足的索引。这种情况下,可以在 SELECT 语句中使用 USE INDEX(indexname) 来强制使用一个索引或者用IGNORE INDEX(indexname)来强制MYSQL忽略索引
147 |
148 | 最后,虽然 EXPLAIN 可以检查我们的 SQL 索引命中情况,但实际上线后,最好配合监控来看下接口的 RT。
149 |
150 | ## 10、说一下数据库的事务隔离?
151 |
152 | 多个线程开启各自事务操作数据库中数据时,数据库系统要负责隔离操作,以保证各个线程在获取数据时的准确性。
153 |
154 | **1、事务不考虑隔离性可能会引发的问题**
155 |
156 | 如果事务不考虑隔离性,可能会引发如下问题:
157 |
158 | - (1)脏读
159 | 脏读指一个事务读取了另外一个事务未提交的数据。
160 |
161 | 这是非常危险的,假设A向B转帐100元,对应sql语句如下所示
162 |
163 | ```java
164 | 1.update account set money=money+100 where name='B';
165 | 2.update account set money=money-100 where name='A';
166 | ```
167 | 当第1条 SQL 执行完,第2条还没执行(A 未提交时),如果此时 B 查询自己的帐户,就会发现自己多了 100 元钱。如果 A 等 B 走后再回滚,B 就会损失 100 元。
168 |
169 | - (2)不可重复读
170 | 不可重复读指在一个事务内读取表中的某一行数据,多次读取结果不同。
171 |
172 | 例如银行想查询 A 帐户余额,第一次查询A帐户为 200 元,此时A向帐户内存了 100 元并提交了,银行接着又进行了一次查询,此时 A 帐户为 300 元了。银行两次查询不一致,可能就会很困惑,不知道哪次查询是准的。
173 |
174 | 不可重复读和脏读的区别是,脏读是读取前一事务未提交的脏数据,不可重复读是重新读取了前一事务已提交的数据。
175 |
176 | 很多人认为这种情况就对了,无须困惑,当然是后面的为准。我们可以考虑这样一种情况,比如银行程序需要将查询结果分别输出到电脑屏幕和写到文件中,结果在一个事务中针对输出的目的地,进行的两次查询不一致,导致文件和屏幕中的结果不一致,银行工作人员就不知道以哪个为准了。
177 |
178 | - (3)虚读(幻读)
179 | 虚读(幻读)是指在一个事务内读取到了别的事务插入的数据,导致前后读取不一致。
180 |
181 | 如丙存款 100 元未提交,这时银行做报表统计 account 表中所有用户的总额为 500 元,然后丙提交了,这时银行再统计发现帐户为 600 元了,造成虚读同样会使银行不知所措,到底以哪个为准。
182 |
183 | 注:以下为在原文的基础上补充的部分
184 |
185 | - (4)丢失修改
186 | 丢失修改(Lost to modify)是指在一个事务读取一个数据时,另外一个事务也访问了该数据,那么在第一个事务中修改了这个数据后,第二个事务也修改了这个数据。这样第一个事务内的修改结果就被丢失,因此称为丢失修改。
187 |
188 | 例如:事务 1 读取某表中的数据 A=20,事务 2 也读取 A=20,事务 1 修改 A=A-1,事务 2 也修改 A=A-1,最终结果 A=19,事务 1 的修改被丢失。
189 |
190 | *不可重复读和幻读区别:*
191 |
192 | 不可重复读的重点是修改,比如多次读取一条记录发现其中某些列的值被修改;幻读的重点在于新增或者删除,比如多次读取一条记录发现记录增多或减少了。
193 |
194 | ## 11、说一下 MySQL 常用的引擎?
195 |
196 | MySQL 常用的引擎主要有`InnoDB`和`MyISQM`两种,其中,在 5.5 版本之前,`MyISAM`是 MySQL 默认的数据库引擎,而 5.5 版本之后默认的数据库引擎是`InnoDB`。`MyISAM`强调的是性能,性能极佳,并且提供了大量的特性,比如全文索引、压缩、空间函数等,但是`MyISAM`不支持事务和行级锁,最大的缺陷就是不支持崩溃后的安全恢复。两者的区别主要如下:
197 | - **是否支持行级锁** : MyISAM 只有表级锁(table-level locking),而InnoDB 支持行级锁(row-level locking)和表级锁,默认为行级锁;
198 | - **是否支持外键**: MyISAM不支持,而InnoDB支持;
199 | - **是否支持事务和崩溃后的安全恢复**:MyISAM 强调的是性能,每次查询具有原子性,其执行速度比 InnoDB 类型更快,但是不提供事务支持。而 InnoDB 提供事务支持,外键等高级数据库功能。 具有事务(commit)、回滚(rollback)和崩溃修复能力(crash recovery capabilities)的事务安全(transaction-safe (ACID compliant))型表。
200 | - **是否支持MVCC**:仅 InnoDB 支持 MVCC。应对高并发事务,MVCC比单纯的加锁更高效;MVCC只在 READ COMMITTED 和 REPEATABLE READ 两个隔离级别下工作;MVCC可以使用`乐观(optimistic)锁`和`悲观(pessimistic)锁`来实现;各数据库中MVCC实现并不统一。
201 |
202 | **那么这两种数据库引擎要如何选择呢?**
203 |
204 | - 一般情况下选择 InnoDB 都是没有问题的,但是某些情况下如果并不在乎可扩展能力和并发能力,也不需要事务支持,也不在乎崩溃后的安全恢复问题的话,选择 MyISAM 也是一个不错的选择。但是一般情况下,我们都是需要考虑到这些问题的。
205 |
206 | ## 12、说一下 MySQL 的行级锁和表级锁?
207 |
208 | - MyISAM 默认采用的是表级锁(table-level locking),而 InnoDB 支持行级锁(row-level locking)和表级锁,但默认采用的是行级锁。
209 | - **表级锁:** MySQL 中锁定`粒度最大`的一种锁,对当前操作的整张表加锁,实现简单,资源消耗也比较少,加锁快,不会出现死锁。其锁定粒度最大,触发锁冲突的概率最高,并发度最低,MyISAM和 InnoDB引擎都支持表级锁。
210 | - **行级锁:** MySQL中锁定`粒度最小`的一种锁,只针对当前操作的行进行加锁。 行级锁能大大减少数据库操作的冲突。其加锁粒度最小,并发度高,但加锁的开销也最大,加锁慢,会出现死锁。
211 |
212 | **InnoDB 引擎中锁的算法有三种:**
213 | - Record lock:单个行记录上的锁
214 | - Gap lock:间隙锁,锁定一个范围,不包括记录本身
215 | - Next-key lock:record+gap 锁定一个范围,包含记录本身
216 |
217 | ## 13、说一下乐观锁和悲观锁?
218 |
219 | **乐观锁**
220 |
221 | - 乐观锁不是数据库自带的,需要我们自己去实现。乐观锁是指操作数据库时(更新操作),想法很乐观,认为这次的操作不会导致冲突,在操作数据时,并不进行任何其他的特殊处理(也就是不加锁),而在进行更新后,再去判断是否有冲突了。
222 |
223 | - 通常实现是这样的:在表中的数据进行操作时(更新),先给数据表加一个版本(version)字段,每操作一次,将那条记录的版本号加1。也就是先查询出那条记录,获取出version字段,如果要对那条记录进行操作(更新),则先判断此刻version的值是否与刚刚查询出来时的version的值相等,如果相等,则说明这段期间,没有其他程序对其进行操作,则可以执行更新,将version字段的值加1;如果更新时发现此刻的version值与刚刚获取出来的version的值不相等,则说明这段期间已经有其他程序对其进行操作了,则不进行更新操作。
224 |
225 | **悲观锁**
226 |
227 | - 与乐观锁相对应的就是悲观锁了。悲观锁就是在操作数据时,认为此操作会出现数据冲突,所以在进行每次操作时都要通过获取锁才能进行对相同数据的操作,这点跟java中的synchronized很相似,所以悲观锁需要耗费较多的时间。另外与乐观锁相对应的,悲观锁是由数据库自己实现了的,要用的时候,我们直接调用数据库的相关语句就可以了。
228 |
229 | - 说到这里,由悲观锁涉及到的另外两个锁概念就出来了,它们就是共享锁与排它锁。共享锁和排它锁是悲观锁的不同的实现,它俩都属于悲观锁的范畴。
230 |
231 | > 引自: https://www.cnblogs.com/zousong/p/10513372.html
232 |
233 | ## 14、MySQL 问题排查都有哪些手段?
234 |
235 | 详情可参考: https://juejin.im/post/5c8375bc5188257fdd0bd252#heading-14
236 |
237 | ## 15、如何做 MySQL 的性能优化?
238 |
239 | 这个问题太大了,具体可以参考[Mysql高性能优化规范建议](https://www.cnblogs.com/huchong/p/10219318.html),不过一般对于 MySQL 方面的优化问题,很多时候指的是 SQL 查询很慢之类的问题,对于这类问题怎么分析呢?
240 |
241 | 在业务系统中,除了使用主键进行的查询,其他的我都会在测试库上测试其耗时,慢查询的统计主要由运维在做,会定期将业务中的慢查询反馈给我们.
242 |
243 | 慢查询的优化首先要搞明白慢的原因是什么? 是查询条件没有命中索引?是 load 了不需要的数据列?还是数据量太大?
244 |
245 | 所以优化也是针对这三个方向来的:
246 |
247 | - 首先分析语句,看看是否 load 了额外的数据,可能是查询了多余的行并且抛弃掉了,可能是加载了许多结果中并不需要的列,对语句进行分析以及重写.
248 | - 分析语句的执行计划,然后获得其使用索引的情况,之后修改语句或者修改索引,使得语句可以尽可能的命中索引.
249 | - 如果对语句的优化已经无法进行,可以考虑表中的数据量是否太大,如果是的话可以进行横向或者纵向的分表.
250 |
251 | 如果有时间,推荐看这篇更详细的文章分析 [一条SQL语句执行得很慢的原因有哪些?](https://mp.weixin.qq.com/s?__biz=Mzg2OTA0Njk0OA==&mid=2247485185&idx=1&sn=66ef08b4ab6af5757792223a83fc0d45&chksm=cea248caf9d5c1dc72ec8a281ec16aa3ec3e8066dbb252e27362438a26c33fbe842b0e0adf47&token=79317275&lang=zh_CN#rd)
252 |
253 | > 参考来源:https://mp.weixin.qq.com/s/l9up2dlPniOYO4usoe-dFA
254 |
--------------------------------------------------------------------------------
/distributed system/README.md:
--------------------------------------------------------------------------------
1 | # 分布式系统
2 | ## 一、分布式缓存
3 | ### Memcached
4 | - Memcached 简介
5 | - Memcached的分布式算法简介
6 | - Memcached的数据清除算法
7 | - Memcacehd 的工作流程是怎么样的?
8 | - Memcached 和 Redis 有什么区别?
9 | - Memcached 适用的业务场景有哪些?
10 | - Memcached 不适用哪些业务场景?
11 | - 能够遍历 Memcached 中所有的 item 吗?
12 | - Memcached 集群是怎么工作的?
13 | - Memcached 最大的优势是什么?
14 | - Memcached 和 MySQL 的 query cache 相比,有什么优缺点?
15 | - Memcached 和服务器的 local cache(比如 PHP 的 APC、mmap 文件等)相比,有什么优缺点?
16 | - Memcached 的 cache 机制是怎样的?
17 | - Memcached 如何实现冗余机制?
18 | - Memcached 如何处理容错的?
19 | - 如何将 Memcached 中 item 批量导入导出?
20 | - 如果确实需要把 Memcached 中的 item 批量导出导入,怎么办?
21 | - Memcached 是如何做身份验证的?
22 | - Memcached 的多线程是什么?如何使用它们?
23 | - Memcached 能接受的 key 的最大长度是多少?
24 | - Memcached 对 item 的过期时间有什么限制?
25 | - Memcached 最大能存储多大的单个 item?
26 | - 为什么单个 item 的大小被限制在 1M byte 之内?
27 | - 可以在不同的 Memcached 节点上使用大小不等的缓存空间吗?如果这么做之后,Memcached 能够更有效地使用内存吗?
28 | - Memcached 的内存分配器是如何工作的?为什么不适用 malloc/free?为何要使用 slabs?
29 | - Memcached 是原子的吗?
30 | - 什么时候失效的数据项会从缓存中删除?
31 | ### Redis
32 | #### 1、Redis 是什么?都有哪些使用场景?
33 |
34 | 1、Redis本质上是一个Key-Value类型的内存数据库,很像memcached,整个数据库统统加载在内存当中进行操作,定期通过异步操作把数据库数据flush到硬盘上进行保存。
35 | 2、Redis最适合所有数据in-momory的场景,虽然Redis也提供持久化功能,但实际更多的是一个disk-backed的功能,跟传统意义上的持久化有比较大的差别。
36 |
37 | 那么可能大家就会有疑问,似乎Redis更像一个加强版的Memcached,那么何时使用Memcached,何时使用Redis呢?
38 |
39 | 如果简单地比较Redis与Memcached的区别,大多数都会得到以下观点:
40 |
41 | Redis不仅仅支持简单的k/v类型的数据,同时还提供list,set,zset,hash等数据结构的存储。
42 | Redis支持数据的备份,即master-slave模式的数据备份。
43 | Redis支持数据的持久化,可以将内存中的数据保持在磁盘中,重启的时候可以再次加载进行使用。
44 |
45 | (1)会话缓存(Session Cache)
46 |
47 | 最常用的一种使用Redis的情景是会话缓存(session cache)。
48 |
49 | 用Redis缓存会话比其他存储(如Memcached)的优势在于:Redis提供持久化。当维护一个不是严格要求一致性的缓存时,如果用户的购物车信息全部丢失,大部分人都会不高兴的,现在,他们还会这样吗?
50 |
51 | 幸运的是,随着 Redis 这些年的改进,很容易找到怎么恰当的使用Redis来缓存会话的文档。甚至广为人知的商业平台Magento也提供Redis的插件。
52 |
53 | (2)全页缓存(FPC)
54 |
55 | 除基本的会话token之外,Redis还提供很简便的FPC平台。回到一致性问题,即使重启了Redis实例,因为有磁盘的持久化,用户也不会看到页面加载速度的下降,这是一个极大改进,类似PHP本地FPC。
56 |
57 | 再次以Magento为例,Magento提供一个插件来使用Redis作为全页缓存后端。
58 |
59 | 此外,对WordPress的用户来说,Pantheon有一个非常好的插件 wp-redis,这个插件能帮助你以最快速度加载你曾浏览过的页面。
60 |
61 | (3)队列
62 |
63 | Reids在内存存储引擎领域的一大优点是提供 list 和 set 操作,这使得Redis能作为一个很好的消息队列平台来使用。Redis作为队列使用的操作,就类似于本地程序语言(如Python)对 list 的 push/pop 操作。
64 |
65 | 如果你快速的在Google中搜索“Redis queues”,你马上就能找到大量的开源项目,这些项目的目的就是利用Redis创建非常好的后端工具,以满足各种队列需求。例如,Celery有一个后台就是使用Redis作为broker,你可以从这里去查看。
66 |
67 | (4)排行榜/计数器
68 |
69 | Redis在内存中对数字进行递增或递减的操作实现的非常好。集合(Set)和有序集合(Sorted Set)也使得我们在执行这些操作的时候变的非常简单,Redis只是正好提供了这两种数据结构。
70 |
71 | 所以,我们要从排序集合中获取到排名最靠前的10个用户–我们称之为“user_scores”。
72 |
73 | 当然,这是假定你是根据你用户的分数做递增的排序。如果你想返回用户及用户的分数,你需要这样执行:
74 |
75 | ```java
76 | ZRANGE user_scores 0 10 WITHSCORES
77 | ```
78 | Agora Games就是一个很好的例子,用Ruby实现的,它的排行榜就是使用Redis来存储数据的,你可以在这里看到。
79 |
80 | (5)发布/订阅
81 |
82 | 最后(但肯定不是最不重要的)是Redis的发布/订阅功能。
83 |
84 | 发布/订阅的使用场景确实非常多,我已看见人们在社交网络连接中使用,还可作为基于发布/订阅的脚本触发器,甚至用Redis的发布/订阅功能来建立聊天系统!(不,这是真的,你可以去核实)。
85 |
86 | Redis提供的所有特性中,我感觉这个是喜欢的人最少的一个,虽然它为用户提供如此多功能。
87 | #### 2、Redis 有哪些功能?
88 |
89 | #### 3、Redis 和 memecache 有什么区别?
90 | - Master写内存快照,save命令调度rdbSave函数,会阻塞主线程的工作,当快照比较大时对性能影响是非常大的,会间断性暂停服务,所以Master最好不要写内存快照。
91 | - Master AOF持久化,如果不重写AOF文件,这个持久化方式对性能的影响是最小的,但是AOF文件会不断增大,AOF文件过大会影响Master重启的恢复速度。
92 | Master最好不要做任何持久化工作,包括内存快照和AOF日志文件,特别是不要启用内存快照做持久化,如果数据比较关键,某个Slave开启AOF备份数据,策略为每秒同步一次。
93 | - Master调用BGREWRITEAOF重写AOF文件,AOF在重写的时候会占大量的CPU和内存资源,导致服务load过高,出现短暂服务暂停现象。
94 | - Redis主从复制的性能问题,为了主从复制的速度和连接的稳定性,Slave和Master最好在同一个局域网内。
95 |
96 | #### 4、Redis 为什么是单线程的?
97 | #### 5、什么是缓存穿透?怎么解决?
98 | #### 6、Redis 支持的数据类型有哪些?
99 | - String、List、Set、Sorted Set、hash。
100 | #### 7、Redis 支持的 java 客户端都有哪些?
101 | - Redisson、Jedis、lettuce等等,官方推荐使用Redisson。
102 | #### 8、Jedis 和 redisson 有哪些区别?
103 | - Jedis是Redis的Java实现的客户端,其API提供了比较全面的Redis命令的支持;
104 | - Redisson实现了分布式和可扩展的Java数据结构,和Jedis相比,功能较为简单,不支持字符串操作,不支持排序、事务、管道、分区等Redis特性; - Redisson的宗旨是促进使用者对Redis的关注分离,从而让使用者能够将精力更集中地放在处理业务逻辑上。
105 | #### 9、怎么保证缓存和数据库数据的一致性?
106 | #### 10、Redis 持久化有几种方式?
107 | - 1、快照(snapshots)
108 |
109 | 缺省情况情况下,Redis把数据快照存放在磁盘上的二进制文件中,文件名为dump。rdb。你可以配置Redis的持久化策略,例如数据集中每N秒钟有超过M次更新,就将数据写入磁盘;或者你可以手工调用命令SAVE或BGSAVE。
110 |
111 | **工作原理**
112 |
113 | - Redis forks。
114 | - 子进程开始将数据写到临时RDB文件中。
115 | - 当子进程完成写RDB文件,用新文件替换老文件。
116 | - 这种方式可以使Redis使用copy-on-write技术。
117 | - 2、AOF
118 |
119 | 快照模式并不十分健壮,当系统停止,或者无意中Redis被kill掉,最后写入Redis的数据就会丢失。这对某些应用也许不是大问题,但对于要求高可靠性的应用来说,Redis就不是一个合适的选择。
120 |
121 | Append-only文件模式是另一种选择。你可以在配置文件中打开AOF模式。
122 |
123 | - 3、虚拟内存方式
124 |
125 | 当你的key很小而value很大时,使用VM的效果会比较好。因为这样节约的内存比较大。当你的key不小时,可以考虑使用一些非常方法将很大的key变成很大的value,比如你可以考虑将key,value组合成一个新的value。
126 |
127 | vm-max-threads这个参数,可以设置访问swap文件的线程数,设置最好不要超过机器的核数,如果设置为0,那么所有对swap文件的操作都是串行的。可能会造成比较长时间的延迟,但是对数据完整性有很好的保证。
128 |
129 | 自己测试的时候发现用虚拟内存性能也不错。如果数据量很大,可以考虑分布式或者其他数据库
130 | #### 11、Redis 怎么实现分布式锁?
131 | #### 12、Redis 分布式锁有什么缺陷?
132 | #### 13、Redis 如何做内存优化?
133 | #### 14、Redis 淘汰策略有哪些?
134 | #### 15Redis 常见的性能问题有哪些?该如何解决?
135 |
136 | > 整理来源:
137 | 1、https://mp.weixin.qq.com/s/HMHTEv9WGgTDPtd-iaiEOA
138 | 2、https://juejin.im/post/5cb13b4d6fb9a0687b7dd0bd#heading-42
139 |
140 |
141 | ## 二、分布式服务框架
142 | ### Dubbo
143 | - Dubbo简介
144 | - 待续
145 |
146 | ## 三、分布式协调服务
147 | ### Zookeeper
148 | - 简述Zookeeper
149 | - 简述ZAB协议
150 | - 简述Paxos算法
151 | - ZK如何保证数据的一致性?
152 | - Dubbo简介及以Zookeeper为注册中心
153 | - Zookeeper的leader选举过程
154 | - 2PC and 3PC
155 | - 简述Zookeeper的watcher
156 | - 简述ZAB集群数据同步的过程
157 | - 简述Zookeeper中的ACL
158 | - Zookeeper底层是如何实现数据一致性的?
159 | - Zookeeper在yarn框架中如何实现避免脑裂的?
160 |
161 | ## 四、分布式消息队列
162 | ### RabbitMQ
163 | - 什么是RabbitMQ?
164 | - 为什么要使用RabbitMQ?
165 | - 消息队列的优缺点?
166 | - RabbitMQ 与 Kafka 有什么区别?
167 | - RabbitMQ 的使用场景有哪些?
168 | - RabbitMQ 有哪些重要的角色?
169 | - RabbitMQ 有哪些重要的组件?
170 | - RabbitMQ 中 vhost 的作用是什么?
171 | - RabbitMQ 的消息是怎么发送的?
172 | - RabbitMQ 怎么保证消息的稳定性?
173 | - RabbitMQ 怎么避免消息丢失?
174 | - 要保证消息持久化成功的条件有哪些?
175 | - RabbitMQ 持久化有什么缺点?
176 | - RabbitMQ 有几种广播类型?
177 | - RabbitMQ 怎么实现延迟消息队列?
178 | - RabbitMQ 集群有什么用?
179 | - RabbitMQ 节点的类型有哪些?
180 | - RabbitMQ 集群搭建需要注意哪些问题?
181 | - RabbitMQ 每个节点是其他节点的完整拷贝吗?为什么?
182 | - RabbitMQ 集群中唯一一个磁盘节点崩溃了会发生什么情况?
183 | - RabbitMQ 对集群节点停止顺序有要求吗?
184 | ### Kafka
185 | - Kafka 都有哪些特点?
186 | - 请简述下你在哪些场景下会选择 Kafka?
187 | - 简述Kafka 的设计架构
188 | - Kafka 分区的目的
189 | - Kafka 是如何做到消息的有序性的?
190 | - Kafka 的高可靠性是怎么实现的?
191 | - 请谈一谈 Kafka 数据一致性原理
192 | - ISR、OSR、AR 是什么?
193 | - LEO、HW、LSO、LW等分别代表什么
194 | - Kafka 在什么情况下会出现消息丢失?
195 | - 怎么尽可能保证 Kafka 的可靠性
196 | - 消费者和消费者组有什么关系?
197 | - Kafka 的每个分区只能被一个消费者线程,如何做到多个线程同时消费一个分区?
198 | - 数据传输的事务有几种?
199 | - Kafka 消费者是否可以消费指定分区消息?
200 | - Kafka消息是采用Pull模式,还是Push模式?
201 | - 如何为Kafka集群选择合适的Topics/Partitions数量
202 | - 待续
203 |
204 | ## 五、分布式搜索引擎
205 |
206 | ### Elasticsearch
207 | - Elasticsearch简介
208 |
209 | ### Solr
210 | 
211 | - [1、Solr简介](https://github.com/bigrotor187/awesome-java-interview/blob/master/distributed%20system/README.md#1solr%E7%AE%80%E4%BB%8B)
212 | - [2、简述Solr的倒排索引](https://github.com/bigrotor187/awesome-java-interview/tree/master/distributed%20system#2%E7%AE%80%E8%BF%B0solr%E7%9A%84%E5%80%92%E6%8E%92%E7%B4%A2%E5%BC%95)
213 | - [3、为什么要使用Solr?](https://github.com/bigrotor187/awesome-java-interview/tree/master/distributed%20system#3%E4%B8%BA%E4%BB%80%E4%B9%88%E8%A6%81%E4%BD%BF%E7%94%A8solr)
214 | - [4、Solr和elasticsearch的区别?](https://github.com/bigrotor187/awesome-java-interview/tree/master/distributed%20system#4solr%E5%92%8Celasticsearch%E7%9A%84%E5%8C%BA%E5%88%AB)
215 |
216 | #### 1、Solr简介
217 | - Solr 是一个 Java 开发的基于 Lucene 的`企业级`、`开源`、`全文搜索`平台。它采用的是`反向索引`,即从关键字到文档的映射过程。
218 | - Solr 的资源`Document`为对象进行存储,每个文档由一系列的`Field`构成,每个`Field`表示资源的一个属性。 文档的`Field`可以被索引,以提供高性能的搜索效率。 一般情况下文档都包含一个能唯一表示该文档的id字段。
219 |
220 | #### 2、简述Solr的倒排索引
221 | - 倒排索引就是从文档内容到文档序号的过程,将文档内容用solr自带分词器进行分词,然后作为索引,用二分法将关键字与排序号的索引进行匹配,进而查找到对应文档。
222 |
223 | > 【注】可参考:1、https://blog.csdn.net/chunlei_zhang/article/details/38520315
224 | 2、https://blog.csdn.net/hu948162999/article/details/42463043
225 | #### 3、为什么要使用Solr?
226 | - Solr 是一个 Java 开发的基于 Lucene 的`企业级`、`开源`、`全文搜索`平台,严格来说,Lucene 负责数据存储,而 Solr 作为一个引擎提供搜索和插入功能,跟数据库的解释器是一样的。但是,如果数据库中有一个字段存了很长的文本,比如存了 1000 个汉字,现在想要从中搜一个词的时候,普通的数据库会使用 like 去查询,遍历整个文本去模糊匹配,效率很低。
227 | - 所以,为了解决这个问题,自然而然地使用全文搜索工具是最好地。比如 lucene 所作的就是分词,然后去匹配分词的词中是否有想搜的词即可。而 Solr 正是基于 Lucene 实现的,使用 Solr 的检索功能可以大大提高检索效率。
228 | #### 4、Solr和elasticsearch的区别?
229 | - 共同点:
230 | - solr 和 elasticsearch 都是基于 Lucene 实现的。
231 | - 不同点:
232 | - 1、solr 利用 zookeeper 进行分布式管理,而 elasticsearch 自身带有分布式协调管理功能;
233 | - 2、solr 比 elasticsearch 实现更加全面,solr 官方提供的功能更多,而 elasticsearch 本身更注 重于核心功能,高级功能多由第三方插件提供;
234 | - 3、solr 在传统的搜索应用中表现好于 elasticsearch,而 elasticsearch 在实时搜索应用方面比 solr 表现好。
235 | - 最后有必要说明一下传统搜索和实时搜索:
236 | - 传统搜索是从静态数据库中筛选出符合条件的结果,这种结果往往是不可变得、静态的。而实时搜索则是说用户对于搜索的结果是实时变化的。
237 | - 传统搜索比如电商这种,实时搜索参考谷歌,百度,这种实时搜索。
238 |
239 | ## 六、分布式事务
240 | - 刚性分布式事务
241 | - 柔性分布式事务
242 | - 两阶段提交协议&三阶段提交协议
243 | - 一致性哈希算法
244 |
--------------------------------------------------------------------------------
/framework/README.md:
--------------------------------------------------------------------------------
1 | |[Spring](https://github.com/bigrotor187/awesome-java-interview/tree/master/framework#spring)|[SpringMVC](https://github.com/bigrotor187/awesome-java-interview/tree/master/framework#springmvc)|[Mybatis](https://github.com/bigrotor187/awesome-java-interview/tree/master/framework#mybatis)|[SpringBoot](https://github.com/bigrotor187/awesome-java-interview/tree/master/framework#springboot)|[Hibernate](https://github.com/bigrotor187/awesome-java-interview/tree/master/framework#hibernate)|[Redis](https://github.com/bigrotor187/awesome-java-interview/tree/master/framework#redis)|
2 | |------|---------|-------|----------|---------|------|
3 |
4 | # Spring
5 |
6 | ## Spring Framework
7 |
8 | - [1、Spring 是如何简化 Java 开发的?](https://github.com/bigrotor187/awesome-java-interview/blob/master/framework/README.md#1spring-%E6%98%AF%E5%A6%82%E4%BD%95%E7%AE%80%E5%8C%96-java-%E5%BC%80%E5%8F%91%E7%9A%84)
9 | - [2、什么是 Spring Framework?](https://github.com/bigrotor187/awesome-java-interview/blob/master/framework/README.md#2%E4%BB%80%E4%B9%88%E6%98%AF-spring-framework)
10 | - [3、Spring Framework 有哪些优点?](https://github.com/bigrotor187/awesome-java-interview/blob/master/framework/README.md#3spring-framework-%E6%9C%89%E5%93%AA%E4%BA%9B%E4%BC%98%E7%82%B9)
11 | - [4、Spring 有哪些子项目吗?请简要描述。](https://github.com/bigrotor187/awesome-java-interview/blob/master/framework/README.md#4spring-%E6%9C%89%E5%93%AA%E4%BA%9B%E5%AD%90%E9%A1%B9%E7%9B%AE%E5%90%97%E8%AF%B7%E7%AE%80%E8%A6%81%E6%8F%8F%E8%BF%B0)
12 | - [5、Spring 框架中用到了哪些设计模式?请举例说明。](https://github.com/bigrotor187/awesome-java-interview/blob/master/framework/README.md#5spring-%E6%A1%86%E6%9E%B6%E4%B8%AD%E7%94%A8%E5%88%B0%E4%BA%86%E5%93%AA%E4%BA%9B%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F%E8%AF%B7%E4%B8%BE%E4%BE%8B%E8%AF%B4%E6%98%8E)
13 | - [6、Spring 有哪些最佳实践?](https://github.com/bigrotor187/awesome-java-interview/blob/master/framework/README.md#6spring-%E6%9C%89%E5%93%AA%E4%BA%9B%E6%9C%80%E4%BD%B3%E5%AE%9E%E8%B7%B5)
14 |
15 | ### **1、Spring 是如何简化 Java 开发的?**
16 |
17 | 为了降低 Java 开发的复杂性,Spring 采取了以下 4 种关键策略:
18 | - 基于 POJO 的轻量级和最小侵入性编程;
19 | - 通过依赖注入和面向接口实现松耦合;
20 | - 基于切面和惯例进行声明式编程;
21 | - 通过切面和模板减少样板式代码。
22 |
23 | ### **2、什么是 Spring Framework?**
24 |
25 | Spring 是一个开源框架,Spring 诞生之初的主要目的是作为 EJB 的轻量级替代品,旨在降低应用程序开发的复杂度。它增强了 POJO,使之具备了之前只有 EJB 和其他企业级 Java 规范才具有的功能。
26 | - Spring 是轻量级、松散耦合的。
27 | > 它的轻量级主要是相对于 EJB 而言。但是随着 Spring 体系越来越庞大,添加 Spring 的依赖管理越来越耗时,写配置挤占了写应用程序逻辑的时间,所以后来推出了 Spring Boot。
28 | - Spring 具有分层体系结构,允许用户选择组件,同时为 J2EE 应用程序开发提供了一个有凝聚力的框架。
29 | - Spring 可以继承其他框架,如 Spring MVC、Hibernate、Mybatis 等,所以又被称为框架饿的框架(粘合剂、脚手架)
30 |
31 | ### **3、Spring Framework 有哪些优点?**
32 | - 轻量级:在开发中使用框架会有一点点开销,但不会像重量级的 EJB 一样
33 | - 控制反转(IOC):也叫依赖注入,Spring 容器负责处理各种对象的依赖关系,而不是创建或查找依赖对象
34 | - 面向切面编程(AOP):Spring 支持 AOP 将业务逻辑与系统服务分开
35 | - IOC 容器:它管理 Spring Bean 生命周期和项目特定配置
36 | - MCV 框架(Spring Mvc):用于创建 Web 应用程序或 RESTful Web 服务,能够返回 XML / JSON 响应
37 | - 事务管理:通过使用 Java 注解或 Spring Bean XML 配置文件,减少 JDBC 操作和文件上传等的样板代码量,适程序更加简洁
38 | - 异常处理:Spring 提供了一个方便的 API,用于将特定技术的异常转换为非检查型的异常
39 |
40 | ### **4、Spring 有哪些子项目吗?请简要描述。**
41 | - Core:提供 Spring 框架核心基础部分的关键模块,比如 Ioc 或 DI
42 | - JDBC:此模块启用 JDBC 抽象层,无需对特定供应商数据库执行 JDBC 编码
43 | - ORM 集成:为流行的对象映射 API 提供集成,例如 JPA、JDO、Hibernate、Mybatis 等
44 | - Web:面向 Web 的集成模块,提供多部分文件上载,Servlet 监听器和面向 Web 的应用程序上下文功能
45 | - MVC framework:一个实现了模型-视图-控制设计模式的 Web 模块
46 | - AOP 模块:面向切面编程的实现允许定义更加简洁的方法-拦截器和切入点
47 |
48 | 
49 |
50 | ### **5、Spring 框架中用到了哪些设计模式?请举例说明。**
51 |
52 | - 代理模式(Proxy Pattern) — 在 AOP 和 remoting 中被用的比较多。
53 | - 单例模式(Singleton Pattern) — 在 Spring 配置文件中定义的 Bean 默认为单例模式。
54 | - 模板方法(Template Method Pattern) —用来解决代码重复的问题。如 RestTemplate、JmsTemplate、JdbcTemplate 。
55 | - 前端控制器(Front Controller) — Spring提供了 DispatcherServlet 来对请求进行分发。
56 | - 视图帮助(View Helper) — Spring 提供了一系列的 JSP 标签,高效宏来辅助将分散的代码整合在视图里。
57 | - 依赖注入(Dependency Injection) — 贯穿于 BeanFactory / ApplicationContext 接口的核心理念。
58 | - 工厂模式(Factory Pattern) — BeanFactory 用来创建对象的实例。
59 | - 适配器模式(Adapter Pattern) — 主要在 Spring Web 和 Spring MVC 模块应用。
60 |
61 |
62 | > 更多详情请参考:
63 | (1)[Spring 框架中的设计模式(一)](http://www.iocoder.cn/Spring/DesignPattern-1/)
64 | (2)[Spring 框架中的设计模式(二)](http://www.iocoder.cn/Spring/DesignPattern-2/)
65 | (3)[Spring 框架中的设计模式(三)](http://www.iocoder.cn/Spring/DesignPattern-3/)
66 | (4)[Spring 框架中的设计模式(四)](http://www.iocoder.cn/Spring/DesignPattern-4/)
67 | (5)[Spring 框架中的设计模式(五)](http://www.iocoder.cn/Spring/DesignPattern-5/)
68 |
69 | ### **6、Spring 有哪些最佳实践?**
70 |
71 | - 为组件使用正确的注解可以一目了然当前层的作用。比如,对于控制层,使用 @Controller,对于业务层,使用 @Service, 对于 DAO 层使用 @Repository。
72 | - 可以根据具体用途划分 Spring Bean,如 spring-jdbc.xml, spring-security.xml 等。
73 | - 尽可能地配置 bean 依赖项,尽量避免自动装配。
74 | - 对于应用程序级的属性,最好的方法是创建属性文件并在 Spring Bean 的配置文件中读取它。
75 |
76 |
77 | > 更多详情请参考:[spring-best-practices](https://www.journaldev.com/2696/spring-interview-questions-and-answers#spring-best-practices)
78 |
79 |
80 | ## Spring Bean
81 | - [1、什么是 Spring Bean?](https://github.com/bigrotor187/awesome-java-interview/blob/master/framework/README.md#1%E4%BB%80%E4%B9%88%E6%98%AF-spring-bean)
82 | - [2、Spring Bean 配置文件的重要性是什么?](https://github.com/bigrotor187/awesome-java-interview/blob/master/framework/README.md#2spring-bean-%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6%E7%9A%84%E9%87%8D%E8%A6%81%E6%80%A7%E6%98%AF%E4%BB%80%E4%B9%88)
83 | - [3、Spring Bean 有哪些配置方式?](https://github.com/bigrotor187/awesome-java-interview/blob/master/framework/README.md#3spring-bean-%E6%9C%89%E5%93%AA%E4%BA%9B%E9%85%8D%E7%BD%AE%E6%96%B9%E5%BC%8F)
84 | - [4、Spring Bean 支持哪几种 Bean Scope?](https://github.com/bigrotor187/awesome-java-interview/blob/master/framework/README.md#4spring-bean-%E6%94%AF%E6%8C%81%E5%93%AA%E5%87%A0%E7%A7%8D-bean-scope)
85 | - [5、Spring Bean 的生命周期是什么样的?](https://github.com/bigrotor187/awesome-java-interview/blob/master/framework/README.md#5spring-bean-%E7%9A%84%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F%E6%98%AF%E4%BB%80%E4%B9%88%E6%A0%B7%E7%9A%84)
86 | - [6、Spring 中单例 Bean 是线程安全的吗?](https://github.com/bigrotor187/awesome-java-interview/blob/master/framework/README.md#6spring-%E4%B8%AD%E5%8D%95%E4%BE%8B-bean-%E6%98%AF%E7%BA%BF%E7%A8%8B%E5%AE%89%E5%85%A8%E7%9A%84%E5%90%97)
87 | - [7、Spring Bean 是否提供线程安全性?](https://github.com/bigrotor187/awesome-java-interview/blob/master/framework/README.md#7spring-bean-%E6%98%AF%E5%90%A6%E6%8F%90%E4%BE%9B%E7%BA%BF%E7%A8%8B%E5%AE%89%E5%85%A8%E6%80%A7)
88 | - [8、Spring 有哪些依赖注入的方式?或者说 Spring 是如何注入 bean 的?](https://github.com/bigrotor187/awesome-java-interview/blob/master/framework/README.md#8spring-%E6%9C%89%E5%93%AA%E4%BA%9B%E4%BE%9D%E8%B5%96%E6%B3%A8%E5%85%A5%E7%9A%84%E6%96%B9%E5%BC%8F%E6%88%96%E8%80%85%E8%AF%B4-spring-%E6%98%AF%E5%A6%82%E4%BD%95%E6%B3%A8%E5%85%A5-bean-%E7%9A%84)
89 | - [9、Spring Bean 定义是如何生成的?](https://github.com/bigrotor187/awesome-java-interview/blob/master/framework/README.md#9spring-bean-%E5%AE%9A%E4%B9%89%E6%98%AF%E5%A6%82%E4%BD%95%E7%94%9F%E6%88%90%E7%9A%84)
90 | - [10、Spring Bean 定义是如何注册的?](https://github.com/bigrotor187/awesome-java-interview/blob/master/framework/README.md#10spring-bean-%E5%AE%9A%E4%B9%89%E6%98%AF%E5%A6%82%E4%BD%95%E6%B3%A8%E5%86%8C%E7%9A%84)
91 |
92 | ### **1、什么是 Spring Bean?**
93 | - Spring Bean 是由 Spring IoC 容器初始化的 Java 对象。
94 | - Spring Bean 由 Spring IoC 容器实例化,配置,装配和管理。
95 | - Spring Bean 基于用户提供给 IoC 容器的配置元数据 Bean Definition 创建。
96 |
97 | ### **2、Spring Bean 配置文件的重要性是什么?**
98 | - 当使用 Spring Bean 配置文件来定义将由 Spring Context 初始化的所有 Bean 时,在创建 Spring ApplicationContext 实例时,会去读取 spring bean XML 配置文件并初始化这些文件
99 | - 初始化上下文后,可以通过它获取不同的 Bean 实例
100 | - 除了 Spring Bean 的配置之外,该文件还包含 Spring MVC 拦截器,视图解析器以及其他元素,以支持基于注解的配置
101 |
102 | ### **3、Spring Bean 有哪些配置方式?**
103 | - XML 配置
104 | - Java Config 配置
105 | - 注解配置
106 | ### **4、Spring Bean 支持哪几种 Bean Scope?**
107 | - Singleton
108 | - Prototype
109 | - Request
110 | - Session
111 | - Application
112 | ### **5、Spring Bean 的生命周期是什么样的?**
113 | - 首先,需要基于Java或XML bean定义来实例化Spring bean。可能还需要执行一些初始化以使其进入可用状态。
114 | - 之后,当不再需要bean时,它将从IoC容器中删除。
115 |
116 | 
117 |
118 | ### **6、Spring 中单例 Bean 是线程安全的吗?**
119 | - Spring 中单例 Bean 不是线程安全的,因为线程安全是关于执行的,而单例则是一种专注于创建的设计模式
120 | - 线程安全仅仅取决于 bean 本身的实现
121 | - Spring 使用 ThreadLocal 解决线程安全问题,“以空间换时间”的方式为每一个线程都提供了一份变量,因此可以同时访问而互不影响。
122 | > 更多详情请参考:
123 | > (1)[Spring单例与线程安全小结](https://www.cnblogs.com/doit8791/p/4093808.html)
124 | > (2)[聊一聊Spring中的线程安全性](https://juejin.im/post/5a0045ef5188254de169968e#heading-0)
125 |
126 | ### **7、Spring Bean 是否提供线程安全性?**
127 |
128 | - Spring 并没有保证对象的线程安全,需要由开发者自己编写解决线程安全问题的代码。
129 | - Spring 对每个 bean 提供了一个 scope 属性来表示该 bean 的作用域,其中默认的 scope 是 singleton,因此每个上下文只有一个实例。这意味所有线程都共享一个单例实例 Bean,因此存在资源竞争,可能会导致数据不一致。因此,在默认模式下,spring bean不是线程安全的。
130 | - 可以将 Spring Bean 的 scope 从 singleton 修改为 request, prototype or session 来获得线程安全,但是会牺牲一部分性能。
131 |
132 | ### **8、Spring 有哪些依赖注入的方式?或者说 Spring 是如何注入 bean 的?**
133 |
134 | - setter注入
135 | - 构造器注入
136 | - 接口注入
137 |
138 |
139 | ### **9、Spring Bean 定义是如何生成的?**
140 | - bean 定义表示对一个类的描述,所以要先生成 bean 定义,然后把它注册到容器中。
141 | - bean 定义的生成主要有两种方式,一种是基于类本身,如知道了类名或类的 class。还有一种是不知道类本身的信息,但是知道它是由一个其他类的工厂方法返回的。而工厂方法又分为静态的和非静态的,所以我们只能记录下这些工厂方法信息到 bean 定义中,在运行时调用工厂方法,获取 bean 的实例对象。
142 | - 工厂方法这种应用场景不多,所以实际上很少用。
143 |
144 | ### **10、Spring Bean 定义是如何注册的?**
145 | - 使用注解注册 bean 定义
146 | - 标有 @Component 注解的类
147 | - 标有 @Configuration 注解的类
148 | - 标有 @Configuration 注解的类里标有 @Bean 注解的方法返回的类
149 |
150 | > PS:这种方式可以用于业务类的注册,也可以用于 Spring 框架内部的类注册。优点是简单方便,缺点是不够灵活,很难根据一个条件判断来注册不同的 bean 定义。
151 | - 使用 XML 配置注册 bean 定义
152 | - 在标有 @Configuration 注解的类上,使用 @ImportResource 注解引入 XML 配置文件
153 |
154 | > PS:这种方式是在注解里也能使用 XML。建议是尽量不用,优先使用注解的方式,除非是是在历史遗留的系统中。
155 |
156 | - 使用 @Import 注解引入
157 | - 在标有 @Configuration 注解的类上,使用 @Import 注解引入其他标有 @Configuration 注解的类
158 |
159 | > PS:这种方式仅用于没有类路径扫描功能的代码,现在大都基于 SpringBoot,所以这种方式现在很少用了。
160 |
161 | - 使用 ImportSelector 接口注册 bean 定义
162 | ```java
163 | public interface ImportSelector {
164 | String[] selectImports(AnnotationMetadata importingClassMetadata);
165 | }
166 | ```
167 |
168 | > PS:
169 | (1)接口方法返回的是类名称的数组,这些类将会被注册 bean 定义。
170 | (2)在实现这个接口时,可以根据不同的情况返回不同的类名称,这就非常的灵活,实现了动态注册 bean 定义的需求。
171 |
172 | - 使用 ImportBeanDefinitionRegistrar 接口注册 bean 定义
173 | ```java
174 | public interface ImportBeanDefinitionRegistrar {
175 | void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry);
176 | }
177 | ```
178 |
179 | > PS:这个接口没有返回值,所以需要自己写代码直接注册 bean 定义,当然也是非常灵活的。在用法上和上面方法一样,包括接口方法参数的含义也一样。
180 |
181 | - 使用 BeanDefinitionRegistryPostProcessor 接口注册 bean 定义
182 |
183 | ```java
184 | public interface BeanDefinitionRegistryPostProcessor extends BeanFactoryPostProcessor {
185 | void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeanException;
186 | }
187 | ```
188 |
189 | > PS:
190 | (1)`BeanDefinitionRegistryPostProcessor`接口专门为其他类注册 `bean` 定义,通过 `postProcessBeanDefinitionRegistry` 方法来实现;
191 | (2)`BeanDefinitionRegistryPostProcessor`接口有一个非常重要的实现类 `ConfigurationClassPostProcessor`,里面包含了所有 Spring 支持的注册 `bean` 定义方式的实现。
192 | (3)Spring 统一了编程模型,所以 `ConfigurationClassPostProcessor` 类也被注册了 `bean` 定义。
193 |
194 | 更多详情请参考:[品Spring:bean定义上梁山](https://mp.weixin.qq.com/s/FDtjJrPMgciM_W7vUpNVbg)
195 |
196 | ## Spring IoC
197 |
198 | - **[1、什么是 Spring IoC 框架?](https://github.com/bigrotor187/awesome-java-interview/blob/master/framework/README.md#3ioc-%E5%92%8C-di-%E6%9C%89%E4%BB%80%E4%B9%88%E5%8C%BA%E5%88%AB)**
199 | - **[2、什么是依赖注入?](https://github.com/bigrotor187/awesome-java-interview/blob/master/framework/README.md#2%E4%BB%80%E4%B9%88%E6%98%AF%E4%BE%9D%E8%B5%96%E6%B3%A8%E5%85%A5)**
200 | - **[3、IoC 和 DI 有什么区别?](https://github.com/bigrotor187/awesome-java-interview/blob/master/framework/README.md#3ioc-%E5%92%8C-di-%E6%9C%89%E4%BB%80%E4%B9%88%E5%8C%BA%E5%88%AB)**
201 | - **[4、Spring 中有哪几种容器?](https://github.com/bigrotor187/awesome-java-interview/blob/master/framework/README.md#4spring-%E4%B8%AD%E6%9C%89%E5%93%AA%E5%87%A0%E7%A7%8D%E5%AE%B9%E5%99%A8)**
202 | - **[5、Spring 有哪些常用的 BeanFactory 容器?请简要介绍一下。](https://github.com/bigrotor187/awesome-java-interview/blob/master/framework/README.md#5spring-%E6%9C%89%E5%93%AA%E4%BA%9B%E5%B8%B8%E7%94%A8%E7%9A%84-beanfactory-%E5%AE%B9%E5%99%A8%E8%AF%B7%E7%AE%80%E8%A6%81%E4%BB%8B%E7%BB%8D%E4%B8%80%E4%B8%8B)**
203 | - **[6、Spring 有哪些常用的 ApplicationContext 容器?请简要介绍一下。](https://github.com/bigrotor187/awesome-java-interview/blob/master/framework/README.md#6spring-%E6%9C%89%E5%93%AA%E4%BA%9B%E5%B8%B8%E7%94%A8%E7%9A%84-applicationcontext-%E5%AE%B9%E5%99%A8%E8%AF%B7%E7%AE%80%E8%A6%81%E4%BB%8B%E7%BB%8D%E4%B8%80%E4%B8%8B)**
204 | - **[7、Spring IoC 有什么好处/优点?](https://github.com/bigrotor187/awesome-java-interview/blob/master/framework/README.md#7spring-ioc-%E6%9C%89%E4%BB%80%E4%B9%88%E5%A5%BD%E5%A4%84%E4%BC%98%E7%82%B9)**
205 | - **[8、请简述 Spring IoC 的实现机制。](https://github.com/bigrotor187/awesome-java-interview/blob/master/framework/README.md#8%E8%AF%B7%E7%AE%80%E8%BF%B0-spring-ioc-%E7%9A%84%E5%AE%9E%E7%8E%B0%E6%9C%BA%E5%88%B6)**
206 | - **[9、Spring IoC 中有哪些不同类型的事件?](https://github.com/bigrotor187/awesome-java-interview/blob/master/framework/README.md#9spring-ioc-%E4%B8%AD%E6%9C%89%E5%93%AA%E4%BA%9B%E4%B8%8D%E5%90%8C%E7%B1%BB%E5%9E%8B%E7%9A%84%E4%BA%8B%E4%BB%B6)**
207 | - **[10、Spring 中哪种注入 bean 的方式是最好的?为什么?](https://github.com/bigrotor187/awesome-java-interview/blob/master/framework/README.md#10spring-%E4%B8%AD%E5%93%AA%E7%A7%8D%E6%B3%A8%E5%85%A5-bean-%E7%9A%84%E6%96%B9%E5%BC%8F%E6%98%AF%E6%9C%80%E5%A5%BD%E7%9A%84%E4%B8%BA%E4%BB%80%E4%B9%88)**
208 | - **[11、BeanFactory 和 Application 两种容器有什么区别?](https://github.com/bigrotor187/awesome-java-interview/blob/master/framework/README.md#11beanfactory-%E5%92%8C-application-%E4%B8%A4%E7%A7%8D%E5%AE%B9%E5%99%A8%E6%9C%89%E4%BB%80%E4%B9%88%E5%8C%BA%E5%88%AB)**
209 |
210 | ### **1、什么是 Spring IoC 框架?**
211 |
212 | Spring 框架的核心是 Spring IoC 容器,容器通过创建 Bean 对象,将它们装配在一起并配置和管理这些对象的整个生命周期。
213 | - Spring 容器使用**依赖注入**来管理组成应用程序的 Bean 对象。
214 | - 容器通过读取提供的**配置元数据(configuration metadata)**的 Bean Definition 来接收对象进行实例化,配置和组装的指令。
215 | - 该配置元数据的 Bean Definition 可以通过 XML,Java 注解或 Java Config 代码来**提供*。
216 |
217 | ### **2、什么是依赖注入?**
218 |
219 | - 依赖注入是控制反转(IoC)的一个方面,是一个通用概念,表明我们不需要手动创建对象,而是描述应如何创建它们。如果需要,IoC 容器将实例化所需的类。
220 | - 不需要直接在代码中将组件和服务连接在一起,而是描述配置文件中哪些组件需要哪些服务。然后,再由 IoC 容器将它们装配在一起。
221 |
222 | ### **3、IoC 和 DI 有什么区别?**
223 |
224 | - IoC 是目的,DI 是手段,IoC 是指让生成类的方式由传统方式(new)反过来,既程序员不调用 new,需要类的时候由框架注入(DI),是对同一事件不同层面的解读。
225 |
226 | ### **4、Spring 中有哪几种容器?**
227 |
228 | Spring 提供了两种最容器,分别是 `BeanFactory` 和 `ApplicationContext`。
229 | - BeanFactory
230 | - BeanFactory 在 spring-beans 项目中提供,默认会使用懒加载的方式来进行 Bean 对象的初始化。
231 | - Beanfactory 就像是一个生产 Bean 的工厂,BeanFactory API 为 Spring 的 IoC 功能提供了基础,实际上Beanfactory只是一个接口,定义了最基本的方法,它会在客户端要求实例化 Bean 对象。
232 | - ApplicationContext
233 | - ApplicationContext 在 spring-context 项目中提供,并且继承自 BeanFactory 接口,扩展了BeanFactory 接口,在 BeanFactory 基础上提供了国际化等许多高级的扩展实现。默认情况下会自动初始化那些非懒加载的 bean 对象。其内置的一些功能如下:
234 | - MessageSource :管理 message ,实现国际化等功能。
235 | - ApplicationEventPublisher :事件发布。
236 | - ResourcePatternResolver :多资源加载。
237 | - EnvironmentCapable :系统 Environment(profile + Properties)相关。
238 | - Lifecycle :管理生命周期。
239 | - Closable :关闭,释放资源
240 | - InitializingBean:自定义初始化。
241 | - BeanNameAware:设置 beanName 的 Aware 接口。
242 |
243 | ### **5、Spring 有哪些常用的 BeanFactory 容器?请简要介绍一下。**
244 | - BeanFactory 容器中最常用的是 XmlBeanFactory 。它可以根据 XML 文件中定义的内容,创建相应的 Bean。
245 | ### **6、Spring 有哪些常用的 ApplicationContext 容器?请简要介绍一下。**
246 | - ApplicationContext 容器中最常用的主要有以下几种实现:
247 | - ClassPathXmlApplicationContext :从 ClassPath 的 XML 配置文件中读取上下文,并生成上下文定义。应用程序上下文从程序环境变量中取得。
248 | ```java
249 | ApplicationContext context = new ClassPathXmlApplicationContext(“bean.xml”);
250 | ```
251 | - FileSystemXmlApplicationContext :由文件系统中的XML配置文件读取上下文。
252 | ```java
253 | ApplicationContext context = new FileSystemXmlApplicationContext(“bean.xml”);
254 | ```
255 | - XmlWebApplicationContext :由 Web 应用的XML文件读取上下文。例如在 Spring MVC 中使用的情况。
256 | - Spring Boot 中,使用的是 ApplicationContext 容器中的 ConfigServletWebServerApplicationContext。
257 | ### **7、Spring IoC 有什么好处/优点?**
258 | ### **8、请简述 Spring IoC 的实现机制。**
259 | ### **9、Spring IoC 中有哪些不同类型的事件?**
260 | ### **10、Spring 中哪种注入 bean 的方式是最好的?为什么?**
261 | ### **11、BeanFactory 和 Application 两种容器有什么区别?**
262 | - BeanFactory 提供容器的接口,提供并管理 bean 实例
263 | - ApplicationContext 提供容器的接口,容纳应用程序中的所有信息,元数据和 bean ,同时它还扩展了 BeanFactory 接口
264 |
265 |
266 |
267 | ## Spring 注解
268 |
269 | ### **1、什么是基于注解的容器配置?**
270 | ### **2、@Component、@Controller、@Repository、@Service 之间有什么区别?**
271 | ### **3、@RequestMapping 注解是如何工作的?**
272 | ### **4、@Required 注解有什么用?**
273 | ### **5、@Autowired 注解有什么用?**
274 | ### **6、@Qualifier 注解有什么而用?**
275 |
276 | ## Spring AOP
277 |
278 |
279 |
280 | ## Spring 事务
281 |
282 |
283 |
284 | # SpringMVC
285 |
286 | # Mybatis
287 |
288 | # SpringBoot
289 |
290 | # Hibernate
291 |
292 | # Redis
293 |
--------------------------------------------------------------------------------
/img/MySQL命令行查看版本号.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bigrotor187/fucking-java-interview/7633eba6b88fad52a0d26860fb85a7974fff7633/img/MySQL命令行查看版本号.jpg
--------------------------------------------------------------------------------
/img/README.md:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/img/Solr.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bigrotor187/fucking-java-interview/7633eba6b88fad52a0d26860fb85a7974fff7633/img/Solr.png
--------------------------------------------------------------------------------
/img/Spring Framework.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bigrotor187/fucking-java-interview/7633eba6b88fad52a0d26860fb85a7974fff7633/img/Spring Framework.jpg
--------------------------------------------------------------------------------
/img/Spring组件.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bigrotor187/fucking-java-interview/7633eba6b88fad52a0d26860fb85a7974fff7633/img/Spring组件.png
--------------------------------------------------------------------------------
/img/status查看版本号.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bigrotor187/fucking-java-interview/7633eba6b88fad52a0d26860fb85a7974fff7633/img/status查看版本号.jpg
--------------------------------------------------------------------------------
/img/系统函数查看版本号.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bigrotor187/fucking-java-interview/7633eba6b88fad52a0d26860fb85a7974fff7633/img/系统函数查看版本号.jpg
--------------------------------------------------------------------------------