{"id":622,"date":"2018-02-22T17:59:16","date_gmt":"2018-02-22T09:59:16","guid":{"rendered":"https:\/\/blog.jsjs.org\/?p=622"},"modified":"2018-02-22T17:59:16","modified_gmt":"2018-02-22T09:59:16","slug":"%e3%80%8ajava%e6%b7%b1%e5%85%a5%e5%be%ae%e6%9c%8d%e5%8a%a1%e5%8e%9f%e7%90%86%e6%94%b9%e9%80%a0%e6%88%bf%e4%ba%a7%e9%94%80%e5%94%ae%e5%b9%b3%e5%8f%b0%e3%80%8b%e7%9f%a5%e8%af%86%e7%82%b9%e6%a2%b3","status":"publish","type":"post","link":"https:\/\/blog.jsjs.org\/?p=622","title":{"rendered":"\u300aJava\u6df1\u5165\u5fae\u670d\u52a1\u539f\u7406\u6539\u9020\u623f\u4ea7\u9500\u552e\u5e73\u53f0\u300b\u77e5\u8bc6\u70b9\u68b3\u7406\u4e0e\u95ee\u7b54\u603b\u7ed3"},"content":{"rendered":"<h3><a href=\"https:\/\/coding.imooc.com\/class\/174.html?mc_marking=10f2cb6a808e1b203a2888bb2ce6506f&amp;mc_channel=shouji\" target=\"_blank\" rel=\"nofollow noopener\">\u300aJava\u6df1\u5165\u5fae\u670d\u52a1\u539f\u7406\u6539\u9020\u623f\u4ea7\u9500\u552e\u5e73\u53f0\u300b<\/a>\u5355\u4f53\u77e5\u8bc6\u70b9<\/h3>\n<p>\u4e00\u56fe\u80dc\u5343\u8a00<br \/>\n<img decoding=\"async\" title=\"\u300aJava\u6df1\u5165\u5fae\u670d\u52a1\u539f\u7406\u6539\u9020\u623f\u4ea7\u9500\u552e\u5e73\u53f0\u300b\u77e5\u8bc6\u70b9\u68b3\u7406\u4e0e\u95ee\u7b54\u603b\u7ed3_\" src=\"https:\/\/img.mukewang.com\/5a7ed3480001aa3f21631986.png\" alt=\"\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h3><a href=\"https:\/\/coding.imooc.com\/class\/174.html\" target=\"_blank\" rel=\"nofollow noopener\">\u300aJava\u6df1\u5165\u5fae\u670d\u52a1\u539f\u7406\u6539\u9020\u623f\u4ea7\u9500\u552e\u5e73\u53f0\u300b<\/a>\u5fae\u670d\u52a1\u77e5\u8bc6\u70b9<\/h3>\n<p>\u4e00\u56fe\u80dc\u5343\u8a00<br \/>\n<img decoding=\"async\" title=\"\u300aJava\u6df1\u5165\u5fae\u670d\u52a1\u539f\u7406\u6539\u9020\u623f\u4ea7\u9500\u552e\u5e73\u53f0\u300b\u77e5\u8bc6\u70b9\u68b3\u7406\u4e0e\u95ee\u7b54\u603b\u7ed3_\" src=\"https:\/\/img.mukewang.com\/5a7ed35500016cda33762544.png\" alt=\"\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h3><a href=\"https:\/\/coding.imooc.com\/class\/174.html\" target=\"_blank\" rel=\"nofollow noopener\">\u300aJava\u6df1\u5165\u5fae\u670d\u52a1\u539f\u7406\u6539\u9020\u623f\u4ea7\u9500\u552e\u5e73\u53f0\u300b<\/a>\u65e5\u5e38\u7b54\u7591<\/h3>\n<ol>\n<li>\u65e2\u7136\u5df2\u7ecf\u5728session\u6709\u4e86\uff0c\u76f4\u63a5session\u53d6\u5c31\u884c\u4e86\uff0c\u4e3a\u4ec0\u4e48\u8981\u518d\u653ethreadlocal\uff0c\u4e4b\u540e\u518d\u4ecethreadlocal\u6e05\u6389\uff0c\u4e00\u76f4\u4ecesession\u62ff\u4e0d\u5c31\u884c\u4e86\uff1f<\/li>\n<\/ol>\n<p>\u7b54:<br \/>\n\u653e\u5728Threadlocal\u91cc\u9762\uff0c\u662f\u4e3a\u4e86\u540e\u9762\u7684Controller\u3001Service\u3001Dao\u4efb\u4f55\u5730\u65b9\u53ea\u8981\u662f\u5f53\u524d\u4e1a\u52a1\u5904\u7406\u7684\u7ebf\u7a0b\u90fd\u80fd \u76f4\u63a5\u5e76\u4e14\u65b9\u4fbf\u7684 \u83b7\u53d6\u5230\u7528\u6237\u5bf9\u8c61. \u5982\u679c\u6211\u4eec\u4e0d\u505a\u8fd9\u79cd\u5904\u7406\uff0c\u90a3\u53ea\u80fd\u4eceSession\u4e2d\u83b7\u53d6\uff0c\u5f53Service\u91cc\u9762\u8981\u83b7\u53d6user\u7684\u65f6\u5019\uff0cController\u5728\u8c03\u7528service\u65b9\u6cd5\u65f6\u5c31\u5fc5\u987b\u4f20\u9012HttpServletRequest\u8fd9\u79cd\u5bb9\u5668\u76f8\u5173\u53c2\u6570\uff0c\u589e\u52a0\u4e86\u4e1a\u52a1\u4e0e\u5e95\u5c42\u5b9e\u73b0\u7684\u8026\u5408\uff0c\u9020\u6210\u4e1a\u52a1\u5904\u7406\u5173\u6ce8\u70b9\u7684\u589e\u591a\uff1b\u800c\u4e14\u6bcf\u4e2aController\u90fd\u9700\u8981\u63a5\u6536HttpServletRequest\u53c2\u6570\uff0c\u56e0\u4e3a\u4e0d\u80fd\u9884\u4f30\u672a\u6765\u662f\u5426\u8981\u83b7\u53d6user\u5bf9\u8c61\u6765\u903b\u8f91\u5904\u7406\u3002<\/p>\n<p>2 nginx\u7684\u914d\u7f6e\u4e2droot\u548calias\u7684\u533a\u522b\uff1f<\/p>\n<p>\u7b54:<br \/>\nroot\u548calias\u7684\u533a\u522b\u662f\u9171\u7d2b\u7684\uff1a<br \/>\n\u914d\u7f6eroot\u9700\u8981\u8bbf\u95ee\u8def\u5f84\u8981\u53e0\u52a0\u76ee\u5f55\u8def\u5f84\uff0c\u6bd4\u5982\u914d\u7f6e\u4e86<br \/>\nlocation \/images {<br \/>\nroot \/path\/to\/img;<br \/>\n}<br \/>\n\u90a3\u4e48\u6709\u5f20\u56fe\/path\/to\/img\/a.jpg,\u90a3\u4e48\u6d4f\u89c8\u5668\u4e2d\u8bbf\u95ee\u5230\u8fd9\u5f20\u56fe\u7247\u5c31\u9700\u8981http:\/\/localhost:8081\/images\/path\/to\/img\/a.jpg<br \/>\n\u800calias\u5c31\u7b80\u5355\u591a\u4e86\uff0curl\u4e2d\u4e0d\u9700\u8981\u5173\u5fc3\u672c\u5730\u76ee\u5f55\u8def\u5f84<br \/>\nlocation \/images {<br \/>\nalias \/path\/to\/img;<br \/>\n}<br \/>\n<a href=\"http:\/\/localhost:8081\/images\/a.jpg\" target=\"_blank\" rel=\"nofollow noopener\">http:\/\/localhost:8081\/images\/a.jpg<\/a>\u00a0\u8fd9\u6837\u5c31\u80fd\u8bbf\u95ee\uff0c\u6240\u4ee5\u5efa\u8bae\u4f7f\u7528alias\uff0c\u5c24\u5176\u662fwindows\u4e0b ;<br \/>\n\u5982\u679c\u975e\u8981\u4f7f\u7528root\u914d\u7f6e\u7684\u8bdd\uff0c\u90a3\u53ea\u80fd\u4f7f\u7528\u76f8\u5bf9\u8def\u5f84\u4e86\uff0c\u76f8\u5bf9nginx\u7684\u5b89\u88c5\u8def\u5f84\uff0c\u6bd4\u5982<br \/>\n\u4f60\u5c06nginx\u5b89\u88c5\u5728D:\\nginx\u4e0b<br \/>\n\u4f60\u53ef\u4ee5\u5c06\u56fe\u7247\u653e\u5728D:\\nginx\\img,\u6bd4\u5982\u4f60\u60f3\u8bbf\u95eeD:\\nginx\\img\\1.jpg,\u914d\u7f6e\u597d:<br \/>\nlocation \/images {<br \/>\nroot img;<br \/>\n}<br \/>\n\u5c31\u53ef\u4ee5\u901a\u8fc7http:\/\/localhost\/images\/1.jpg\u5c31\u53ef\u4ee5\u4e86\uff0c<br \/>\n\u5426\u5219\u53ef\u4ee5\u4f7f\u7528alias\uff0c\u5c31\u53ef\u4ee5\u4f7f\u7528windows\u7edd\u5bf9\u8def\u5f84\u4e86<\/p>\n<p>3.freemarker\u7684\u90a3\u4e9b\u6587\u4ef6\u54ea\u91cc\u53ef\u4ee5\u4e0b\u8f7d\uff1f\u9759\u6001\u6587\u4ef6\u5728\u54ea\u91cc<\/p>\n<p>\u7b54:<br \/>\nfreemarker\u6587\u4ef6\u5728\u5355\u4f53\u5de5\u7a0bhouse-web\/src\/main\/resources\/templates\u76ee\u5f55\u4e0b\uff0c\u662f\u4ee5.ftl\u7ed3\u5c3e\u7684\u6587\u4ef6<br \/>\n\u56fe\u7247\u6587\u4ef6\u5728\u5355\u4f53\u5de5\u7a0bhouse-web\/src\/main\/resources\/static\u76ee\u5f55\u4e0b<\/p>\n<p>4.datasource \u52a0\u8f7d\u5931\u8d25\uff0c\u7a7a\u6307\u9488\u5f02\u5e38<br \/>\n\u7b54:<br \/>\n\u786e\u4fddmysql\u9a71\u52a8\u53caMybatis-Starter\u5df2\u7ecf\u4f9d\u8d56\uff0chouse-web\u5df2\u7ecf\u4f9d\u8d56\u4e0a\u4e86house-biz\uff0c\u5e76\u4e14\u914d\u7f6e\u6587\u4ef6\u4e2d\u5305\u542b\u6709spring.druid\u7684\u914d\u7f6e<\/p>\n<p>5.\u53d1\u73b0\u6211\u7684spring-boot \u7684\u914d\u7f6e\u6587\u4ef6\u4e0d\u652f\u6301 \u7684druid\u7684 spring.druid.xx\u7684\u5c5e\u6027\u683c\u5f0f,\u53ea\u80fd\u7528spring.datasource.xx\u7684\u683c\u5f0f\uff0c\u8fd9\u662f\u4e3a\u4ec0\u4e48?<\/p>\n<p>\u7b54:<br \/>\nConfigurationProperties\u6ce8\u89e3\u6709\u4e24\u79cd\u4f7f\u7528\u65b9\u5f0f\uff0c\u4e00\u79cd\u662f\u6ce8\u89e3\u5728<em>Properties\u7c7b\u4e0a\uff0c\u4f5c\u7528\u662f\u5c06application.properties(yaml)\u4e0a\u7684\u914d\u7f6e\u7ed1\u5b9a\u5230\u8be5\u7c7b\u5c5e\u6027\u4e0a\uff0c\u53e6\u5916\u4e00\u79cd\u662f\u6ce8\u89e3\u5728Bean\u65b9\u6cd5\u4e0a\uff0c\u4f5c\u7528\u662f\u5c06\u4f5c\u7528\u662f\u5c06application.properties(yaml)\u4e0a\u7684\u914d\u7f6e\u7ed1\u5b9a\u5230\u8be5bean\u65b9\u6cd5\u8fd4\u56de\u5bf9\u8c61\u4e0a\u3002\u524d\u8005\u901a\u8fc7\u6ce8\u89e3\u5904\u7406\u5668\u662f\u53ef\u4ee5\u751f\u6210\/META-INF\/<\/em>metadata.json\u6587\u4ef6,\u7528\u4e8eIDE\u4ee3\u7801\u63d0\u793a\u7684\uff0c\u540e\u8005\u5c31\u65e0\u6cd5\u751f\u6210\u4e5f\u5c31IDE\u4e0d\u80fd\u8fdb\u884c\u63d0\u793a\uff0c\u518d\u8005\uff0c\u5728Bean\u65b9\u6cd5\u4e0a\u6ce8\u89e3@ConditionalOnProperty\u7684property\uff0cIDE\u4e5f\u65e0\u6cd5\u63d0\u4f9b\u63d0\u793a\u3002<\/p>\n<p>\u4f60\u4e5f\u8003\u8651\u4f7f\u7528druid-spring-starter\u6765\u66ff\u6362DruidConfig,\u4e8b\u5148\u8981\u5220\u9664DruidConfig\u3002\u8bfe\u7a0b\u4e2d\u4f7f\u7528DruidConfig\u662f\u66f4\u52a0\u8f7b\u91cf\u53ef\u63a7\u7684\u65b9\u5f0f\u3002<\/p>\n<p>6.\u63d0\u793auserService\u627e\u4e0d\u5230<br \/>\n.\u7b54:<br \/>\n\u8bf7\u68c0\u67e5service\u6ce8\u89e3\u53capackage\u662f\u5426\u5c5e\u4e8e\u542f\u52a8\u7c7b\u6240\u5728package\u7684\u5b50package\u3002\u6240\u6709bean\u627e\u4e0d\u5230\uff0cmapper\u627e\u4e0d\u5230\u7684\u9519\u8bef\uff0c\u8981\u5148\u786e\u4fdd\u542f\u52a8\u7c7b<br \/>\n\u6240\u5728package\u662froot package\uff0cSpringBoot\u9ed8\u8ba4\u4f1a\u626b\u63cfroot package\u4e0b\u9762\u7684\u5b50package\u6765\u53d1\u73b0Spring bean\uff0c\u8fd9\u4e2a\u5c24\u5176\u8981\u6ce8\u610f<\/p>\n<p>7 . Cannot expose session attribute &#8216;user&#8217; because of an existing model object of the same name<br \/>\n\u7b54:<br \/>\n\u6ce8\u91ca\u6389\u540c\u540duser\u7684attribute\u8bbe\u7f6e<\/p>\n<p>8.Error creating bean with name &#8216;userController&#8217;: Unsatisfied dependency expressed through field &#8216;userService&#8217;<br \/>\n\u7b54:<br \/>\n\u9996\u5148\u770b\u5e95\u5c42\u7684mapper bean\uff0cdatasource bean\u521b\u5efa\u662f\u5426\u6b63\u5e38\uff0c\u6570\u636e\u5e93\u6709\u6ca1\u6709\u8fde\u63a5\u4e0a\uff0c\u7136\u540e\u518d\u68c0\u67e5\u4e0bapplication.properties\u7684mybatis\u914d\u7f6e\u662f\u5426\u6b63\u786e<\/p>\n<p>9.\u7528\u6237\u6a21\u5757\u4e00\u822c\u4f5c\u4e3a\u72ec\u7acb\u7684\u670d\u52a1\u6570\u636e\u5e93\uff0c\u6bd4\u5982\u5176\u5b83\u4e1a\u52a1\u6a21\u5757\uff08\u8ba2\u5355\u6a21\u5757\uff09 \u6211\u7684\u6bcf\u7b14\u8ba2\u5355\u90fd\u662f\u8ddf\u4eba\u7ed1\u5b9a\u7684\u3002\u8fd9\u91cc\u662f\u9700\u8981\u7528\u8868join\u7684\u3002\u7c7b\u4f3c\u4e8e\u8fd9\u6837\u7684\u4e1a\u52a1\u6570\u636e\u5e94\u8be5\u6709\u5f88\u591a\uff0c\u8fd9\u6837\u7684\u8868\u7ed3\u6784\u5982\u4f55\u5212\u5206\u5fae\u670d\u52a1\u3002<\/p>\n<p>\u7b54:<br \/>\n\u5fae\u670d\u52a1\u6539\u9020\u65f6\u8981\u4ee5\u9650\u5b9a\u4e0a\u4e0b\u6587\u8fdb\u884c\u62c6\u5206\uff0c\u5047\u8bbe\u8ba2\u5355\u548c\u7528\u6237\u5206\u5c5e\u4e24\u4e2a\u4e0d\u540c\u7684\u9650\u5b9a\u4e0a\u4e0b\u6587\u3002\u6839\u636e\u5b9e\u9645\u7ecf\u9a8c\uff0c\u7528\u6237\u901a\u5e38\u4f5c\u4e3a\u4e00\u4e2a\u6700\u57fa\u7840\u7684\u670d\u52a1\uff0c\u7528\u6237\u6d89\u53ca\u7684\u5173\u8054\u5173\u7cfb\u5f88\u591a\uff0c\u4e3a\u9632\u6b62\u7528\u6237\u670d\u52a1\u53d8\u7684\u8fc7\u4e8e\u5e9e\u5927\uff0c\u5173\u8054\u5173\u7cfb\u5f80\u5f80\u5206\u62c6\u5230\u5176\u5b83\u9886\u57df\u6a21\u578b\u4e2d\u8fdb\u884c\u7ef4\u62a4\uff0c\u6bd4\u5982\u8ba2\u5355\u7528\u6237\u5173\u7cfb\u4f1a\u653e\u5728\u8ba2\u5355\u670d\u52a1\u4e2d\u7ef4\u62a4\u3002<br \/>\n\u5fae\u670d\u52a1\u62c6\u5206\u540e\uff0c\u5bf9\u4e8e\u8ba2\u5355\u67e5\u8be2\u7684\u573a\u666f\uff0c\u53ef\u4ee5\u4ece\u8ba2\u5355\u7528\u6237\u5173\u7cfb\u8868\u4e2d\u7684userid\u6765\u67e5\u8be2\u51fa\u8ba2\u5355id\u5217\u8868\uff0c\u7136\u540e\u901a\u8fc7\u8ba2\u5355id\u5217\u8868\u67e5\u8be2\u8ba2\u5355\u8868\u3002\u5bf9\u4e8e\u591a\u7ef4\u5ea6\u6761\u4ef6\u3001\u5206\u9875\u3001\u8303\u56f4\u67e5\u8be2\u7684\u573a\u666f\u53ef\u4ee5\u5c06\u7528\u6237\u548c\u8ba2\u5355\u8868\u5408\u5e76\u6210\u4e00\u4e2a\u5bbd\u8868\u8f93\u51fa\u5230ES\u4e2d\uff0c\u6765\u89e3\u51b3\u8de8\u5e93join\u7684\u95ee\u9898<\/p>\n<p>10.\u5206\u5e03\u5f0f\u4e8b\u52a1\u548c\u6d88\u606f\u961f\u5217\u7684\u5185\u5bb9\u6709\u6d89\u53ca\u5230\u5417<\/p>\n<p>\u7b54:<br \/>\n\u4f1a\u6709\u6d89\u53ca\uff0c\u56e0\u8bfe\u7a0b\u7bc7\u5e45\u6240\u9650\uff0c\u4f1a\u4ece\u7406\u8bba\u4e0a\u8bb2\u89e3\uff0c\u7f3a\u5c11\u4ee3\u7801\u5b9e\u73b0\u90e8\u5206\uff0c\u8fd8\u8bf7\u89c1\u8c05<\/p>\n<p>11.\u591a\u5e93\u7684\u6570\u636e\u7edf\u8ba1\u95ee\u9898\uff0c\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u62c6\u4e3a\u591a\u5e93\u65f6\uff0c\u8054\u8868\u67e5\u8be2\u7edf\u8ba1\u600e\u4e48\u5904\u7406\uff1f<\/p>\n<p>\u7b54:<br \/>\n\u5982\u679c\u662f\u5e94\u7528\u4e2d\u6709\u590d\u6742\u6761\u4ef6\u67e5\u8be2\u7684\u903b\u8f91\uff0c\u5e94\u8be5\u5c06\u591a\u5f20\u6570\u636e\u8868\u5408\u5e76\u6210\u5bbd\u8868\u540c\u6b65\u5230ES\u4e2d\uff0c\u8fdb\u884c\u67e5\u8be2.<br \/>\n\u6570\u636e\u7edf\u8ba1\u5e94\u8be5\u548c\u5e94\u7528\u5f00\u53d1\u5206\u79bb\uff0c\u7531\u4e13\u95e8\u7684\u56e2\u961f\u8d1f\u8d23\uff0c\u4e00\u822c\u662f\u5c06\u6570\u636e\u8868\u5b9a\u671f\u6216\u5b9e\u65f6\u540c\u6b65\u5230hive\u8868\uff0c\u901a\u8fc7hive sql\u8fdb\u884c\u79bb\u7ebf\u7edf\u8ba1\u3002<\/p>\n<p>12.\u5728mapper\u63a5\u53e3\u4e0a\u6dfb\u52a0\u6ce8\u89e3+SQL(\u6bd4\u5982select(&#8220;select * from &#8230;&#8221;))\u7684\u65b9\u5f0f,\u548c\u8bfe\u7a0b\u4e2d\u63a5\u53e3\u5b9a\u4e49\u5728\u7c7b\u4e2d,SQL\u8bed\u53e5\u5b9a\u4e49\u5728XML\u6587\u4ef6\u4e2d\u8fd9\u79cd\u65b9\u5f0f\uff0c\u4e24\u8005\u4e4b\u95f4\u9664\u4e86\u5b9e\u73b0\u65b9\u5f0f\u4e0d\u540c\u5916\u8fd8\u6709\u5176\u5b83\u533a\u522b\u5417\uff1f<\/p>\n<p>\u7b54:<br \/>\n\u6ce8\u89e3\u65b9\u5f0f\u65e0\u6cd5\u5229\u7528mybatis\u52a8\u6001sql\u7684\u529f\u80fd\uff0c\u5f53sql\u53d8\u591a\u53d8\u590d\u6742\u5c06\u6210\u4e3a\u5669\u68a6\uff1b\u5bf9\u4e8e\u6570\u636e\u5e93\u64cd\u4f5c\u8981\u6c42\u8f83\u9ad8\u7684\u9879\u76ee\u5982\u679c\u8fdb\u884csql\u5ba1\u6838\u5c06\u53d8\u5f97\u4e0d\u65b9\u4fbf\uff1bsql\u4e0e\u4ee3\u7801\u653e\u5728\u4e00\u8d77\uff0c\u4e5f\u96be\u4ee5\u7ef4\u62a4<\/p>\n<p>13.\u670d\u52a1\u7684\u6d88\u8d39\u8005\u9700\u8981\u6ce8\u518c\u5230\u6ce8\u518c\u4e2d\u5fc3\u5417\uff0c\u8fd8\u662f\u53ea\u9700\u8981\u670d\u52a1\u7684\u63d0\u4f9b\u8005\u6ce8\u518c\u5230\u6ce8\u518c\u4e2d\u5fc3\u5c31\u884c?<br \/>\n\u7b54:<br \/>\n\u5bf9\u4e8eSpringCloud Eureka\u53ea\u9700\u8981\u670d\u52a1\u63d0\u4f9b\u8005\u6ce8\u518c,\u4f46\u540c\u65f6\u8981\u6ce8\u610f\u5f88\u591a\u670d\u52a1\u662f \u517c\u5177\u8fd9\u4e24\u79cd\u89d2\u8272\u7684&#8211;\u65e2\u662f\u670d\u52a1\u6d88\u8d39\u8005\u53c8\u662f\u670d\u52a1\u63d0\u4f9b\u8005<\/p>\n<p>14.\u4e3a\u5565\u6211\u5b9e\u4f8b\u5728Eureka DashBoard\u4e0d\u663e\u793aIPxxxx\uff0c\u800c\u662f\u663e\u793a\u673a\u5668\u540d\uff1f<\/p>\n<p>\u7b54:<br \/>\n\u6dfb\u52a0\u4e00\u4e2a\u914d\u7f6eeureka.instance.prefer-ip-address = true\uff0c\u5982\u679c\u8fd8\u662f\u673a\u5668\u540d\u8bf4\u660e\u4f60\u672c\u5730\u53ea\u6709\u4e00\u4e2a\u56de\u73af\u5730\u5740127.0.0.1\uff0c\u90a3\u4e48<br \/>\n\u8fd8\u9700\u8981\u52a0\u4e0aeureka.instance.instance-id=${\u4f60\u7684ip}:${\u4f60\u7684port}\u624d\u884c<\/p>\n<p>15.SpringCloud\u7248\u672c\u4e0eSpringboot\u7684\u7248\u672c\u5bf9\u5e94\u7684\u95ee\u9898<\/p>\n<p>\u7b54:<br \/>\n\u867d\u7136SpringCloud\u7248\u672c\u4e0eSpringBoot\u6ca1\u6709\u5f3a\u5236\u5bf9\u5e94\u5173\u7cfb\uff0c\u4f46\u662f\u8fd8\u662f\u5efa\u8bae\u5728\u9009\u7528SpringCloud\u7248\u672c\u65f6\u8981\u540c\u65f6\u9009\u62e9\u4e0e\u5176\u517c\u5bb9\u7684SpringBoot\u7248\u672c\u3002\u901a\u8fc7http:\/\/projects.spring.io\/spring-cloud\/#quick-start\u8f93\u5165\u4e0d\u540cSpringCloud\u7248\u672c\u8fd4\u56de\u5bf9\u5e94\u7684SpringBoot\u7248\u672c<\/p>\n<p>16.recomHouse\u53d8\u91cf\u6ca1\u6709\u503c\uff0cFreemarker\u62a5\u9519\u7684\u95ee\u9898,FreeMarker template error (DEBUG mode; use RETHROW in production!): The following has evaluated to null or missing: ==&gt; recomHouses [in template &#8220;homepage\/index.ftl&#8221; at line 107, column 27]<\/p>\n<p>\u7b54:<br \/>\nrecomHouses\u6ca1\u6709\u503c\uff0c\u662f\u4e0d\u662f\u8fd8\u6709\u5b66\u5230\u63a8\u8350\u90a3\u4e00\u8282\uff0c\u5efa\u8bae\u5148\u6ce8\u91ca\u6389\uff0c\u7b49\u5b66\u5230\u70ed\u95e8\u63a8\u8350\u518d\u89e3\u5f00<\/p>\n<p>17.mybatis.config-location=classpath:\/mybatis\/mybatis-config.xml\uff0c\u8fd9\u4e2a\u662f\u5199\u5728web\u4e0b\u7684\uff0c\u4f46config.xml\u662f\u5728biz\u4e0b\u7684\uff0c\u6700\u540e\u662f\u600e\u4e48\u627e\u5230\u7684<\/p>\n<p>\u7b54:<br \/>\n\u6700\u540e\u6253\u6210\u4e00\u4e2ajar\u5305\uff0cjar\u5305\u91cc\u9762\u53c8\u5305\u542bbiz\u7684jar\uff0c\u6240\u4ee5\u80fd\u627e\u5230<\/p>\n<p>18.\u80fd\u5426\u7b80\u5355\u4ecb\u7ecd\u4e0b\u670d\u52a1\u62c6\u5206,\u5bf9\u4e8e\u4e00\u4e2a\u50cf\u65e7\u7cfb\u7edf \u7528\u6237\u8868\\\u7ec4\u7ec7\u8868\u83dc\u5355\\\u8fd9\u4e9b\u57fa\u7840\u7684\u771f\u4e0d\u77e5\u9053\u5982\u4f55\u4e0b\u624b\u5440<br \/>\n\u7b54:<br \/>\n\u670d\u52a1\u62c6\u5206\u6d89\u53ca\u5f88\u591a\uff0c\u57fa\u672c\u7684\u62c6\u5206\u539f\u5219\uff0c\u7ec4\u7ec7\u67b6\u6784\uff0c\u9879\u76ee\u7279\u70b9\uff0c\u4e1a\u52a1\u573a\u666f\uff0c\u5386\u53f2\u7ecf\u9a8c\u90fd\u6709\u5173\u7cfb;<br \/>\n\u4ece\u4e1a\u52a1\u529f\u80fd\u4e4b\u4e0a\u6765\u770b\u670d\u52a1\u62c6\u5206\uff0c\u800c\u4e0d\u662f\u6570\u636e\u8868 \uff0c \u5c06\u6bcf\u4e2a \u201c\u8054\u7cfb\u7d27\u5bc6\u7684\u4e1a\u52a1 &#8221; \u5212\u5b9a\u6210\u4e00\u4e2a\u9650\u5b9a\u4e0a\u4e0b\u6587;<br \/>\n\u7136\u540e\u518d\u5206\u6790\u9650\u5b9a\u4e0a\u4e0b\u6587\u5305\u542b\u54ea\u4e9b\u4e1a\u52a1\u6a21\u578b\uff0c\u4e0a\u4e0b\u6587 \u4e4b\u95f4 \u53ef\u4ee5\u5206\u6790\u51fa\u54ea\u4e9b\u5171\u4eab\u6a21\u578b<\/p>\n<p>19.\u6280\u672f\u4e66\u90fd\u6709\u54ea\u4e9b\u63a8\u8350<\/p>\n<p>\u7b54:<br \/>\n\u300aJava TCP\/IP Socket\u7f16\u7a0b\u300b \u7f51\u7edc\u7f16\u7a0b\u5feb\u901f\u5165\u95e8\uff0c\u8bb2\u7684\u901a\u4fd7\u6613\u61c2<br \/>\n\u300aJava\u5e76\u53d1\u7f16\u7a0b\u5b9e\u6218\u300b \u5e76\u53d1\u7f16\u7a0b\u7ecf\u5178\u4e66\uff0c\u5fc5\u8bfb<br \/>\n\u300aEffactive Java 2.0\u300b Java\u7f16\u7a0b\u7684\u6700\u4f73\u5b9e\u8df5\uff0c\u4f9d\u7136\u503c\u5f97\u7ec6\u8bfb<br \/>\n\u300ajava\u5e76\u53d1\u7f16\u7a0b\u7684\u827a\u672f\u300b \u5f15\u5bfc\u4f60\u6df1\u5165JDK\u5e76\u53d1\u5305\u6e90\u7801\uff0c\u5efa\u8bae\u8fb9\u7814\u7a76\u6e90\u7801\u8fb9\u53c2\u8003\u672c\u4e66<br \/>\n\u300a\u4ecePaxos\u5230Zookeeper\u5206\u5e03\u5f0f\u4e00\u81f4\u6027\u539f\u7406\u4e0e\u5b9e\u8df5\u300b \u501f\u52a9zookeeper\u7ec4\u4ef6\u7684\u6df1\u5165\u5256\u6790\uff0c\u8ba9\u4f60\u53ef\u4ee5\u4e86\u89e3\u5206\u5e03\u5f0f\u7cfb\u7edf\u9886\u57df\u7684\u8bbe\u8ba1\u539f\u7406<br \/>\n\u300a\u7cbe\u901aSpring 4.X:\u4f01\u4e1a\u5e94\u7528\u5f00\u53d1\u5b9e\u6218\u7cbe\u901a\u300b \u5982\u679c\u975e\u8981\u63a8\u8350\u4e00\u672cSpring\u7684\u4e66\uff0c\u6211\u89c9\u5f97\u9648\u96c4\u534e\u5199\u7684\u8fd9\u672c\u8fd8\u662f\u4e0d\u9519\u7684\uff0c\u6211\u770b\u8fc7Spring3.x\u4f01\u4e1a\u5e94\u7528\u5f00\u53d1\u5b9e\u6218\uff0c\u53ef\u4ee5\u5f53\u505a\u5b57\u5178\u4e66<br \/>\n\u300aMysql\u6280\u672f\u5185\u5e55\u300b \u7cfb\u5217\u7684\u4e66\uff0c\u53ef\u4ee5\u8ba9\u4f60\u4e86\u89e3Mysql\u7684\u539f\u7406<br \/>\n\u300a\u5927\u578b\u7f51\u7ad9\u6280\u672f\u67b6\u6784-\u6838\u5fc3\u539f\u7406\u4e0e\u6848\u4f8b\u5206\u6790\u300b\u53ca \u300a\u5927\u578b\u7f51\u7ad9\u7cfb\u7edf\u4e0eJava\u4e2d\u95f4\u4ef6\u5b9e\u8df5\u300b \u53ef\u4ee5\u8ba9\u4f60\u4e86\u89e3\u4e92\u8054\u7f51\u7cfb\u7edf\u67b6\u6784\u7684\u6f14\u8fdb\u8fc7\u7a0b<br \/>\n\u300a\u6df1\u5165\u7406\u89e3Java\u865a\u62df\u673a\u300b<\/p>\n<p>20.feign\u7684\u4f5c\u7528\u8fd8\u6709\u54ea\u4e9b\u5e38\u7528\u7684\u5462<\/p>\n<p>\u7b54:\u5b83\u4e5f\u662f\u57fa\u4e8ehttp\uff0c\u8ba9\u4f60\u4ece\u590d\u6742\u7684http\u8bf7\u6c42\u6784\u5efa\u8fc7\u7a0b\u4e2d\u89e3\u8131\u51fa\u6765<\/p>\n<p>21.Spring Cloud Config\u600e\u4e48\u6837<\/p>\n<p>\u7b54\uff1a<br \/>\nSpringCloud Config \u5b83\u76f8\u6bd4\u4e00\u4e9b\u5f00\u6e90\u7684\u5206\u5e03\u5f0f\u914d\u7f6e\u4e2d\u5fc3(Disconf\uff0c Dismond)\u8fd8\u6709\u4e00\u4e9b\u5dee\u8ddd\uff0c\u6bd4\u5982\u5b83\u4e0d\u652f\u6301\u53d8\u66f4\u901a\u77e5<\/p>\n<p>22.\u6211\u4eec\u5e94\u8be5\u5bf9spring boot \u7684\u7ebf\u7a0b\u6c60\u8fdb\u884c\u8bbe\u7f6e\u5427\u3002\u3002\u8fd8\u662f\u9ed8\u8ba4\u7684\u914d\u7f6e\u5c31\u80fd\u4e07\u91d1\u6cb9\u4e86\uff1f<\/p>\n<p>\u7b54:<br \/>\n\u5e76\u53d1\u91cf\u5927\uff0c\u4e1a\u52a1\u5904\u7406\u8017\u65f6\u8f83\u4e45\u7684\u4e1a\u52a1\u573a\u666f\u4e0b\u8981\u5c06\u7ebf\u7a0b\u6570\u5f00\u5927,\u6bd4\u5982\u5982\u679c\u4f60\u4f7f\u7528tomcat\uff0c\u90a3\u4e48\u5728application.properties(yaml)\u4e2d<br \/>\n\u6dfb\u52a0\u914d\u7f6eserver.tomcat.max-threads=2000<\/p>\n<p>23.\u6dfb\u52a0\u6ce8\u89e3Async\u6267\u884c\u5f02\u6b65\u6ca1\u6709\u751f\u6548<\/p>\n<p>\u7b54:<br \/>\nSpring\u5904\u7406\u5f02\u6b65\u662f\u901a\u8fc7AOP\u6765\u5b9e\u73b0\u7684\uff0c\u9700\u8981\u8c03\u7528\u7684Service\u4e0e\u6dfb\u52a0@Async\u65b9\u6cd5\u7684Service\u5206\u5f00\uff0c\u540c\u65f6@Async\u6ce8\u89e3\u7684\u65b9\u6cd5\u4e0d\u80fd\u6709\u8fd4\u56de\u503c\uff08\u6216\u8005\u8fd4\u56deFuture&lt;T&gt;\uff09\uff0c\u4e5f\u4e0d\u80fd\u5b9a\u4e49\u4e3aprivate<\/p>\n<p>24.\u591a\u73af\u5883\u914d\u7f6e\u7684\u65f6,\u662f\u901a\u8fc7pom\u5b9a\u4e49\u591a\u4e2aprofiles,\u8fd8\u662f\u5b9a\u4e49\u591a\u4e2aapplication-*.yml(\u5982\uff1aapplication-dev.yml\uff09\u8fd9\u6837\u7684\u6587\u4ef6<\/p>\n<p>\u7b54:<br \/>\n\u751f\u4ea7\u73af\u5883\u5efa\u8bae\u4f7f\u7528\u7684\u524d\u8005\uff0c\u56e0\u4e3a\u4e0d\u540c\u73af\u5883\uff0c\u4e0d\u6b62\u53ea\u6709application.properties(yaml)\u4e0d\u540c\uff0c\u8fd8\u6709\u5176\u5b83\u914d\u7f6e\u6587\u4ef6\u4e0d\u540c\u73af\u5883\u4e5f\u4e0d\u4e00\u6837\u3002<\/p>\n<p>25.\u6dfb\u52a0\u4f9d\u8d56\u540eIDE\u6ca1\u6709\u751f\u6548<\/p>\n<p>\u7b54:<br \/>\n\u5982\u679c\u4f7f\u7528Eclipse\uff0c\u4f7f\u7528Maven-Update Project..<br \/>\n\u5982\u679c\u4f7f\u7528Idea\uff0c\u9009\u62e9Maven Projects -&gt; reimport all maven projects<\/p>\n<p>26.hystrix\u662f\u4e0d\u662f\u90fd\u8981\u5728\u5404\u4e2a\u670d\u52a1\u8ddf\u7f51\u5173\u90fd\u9700\u8981\u914d\u7f6e\u5b9e\u73b0\u5462<\/p>\n<p>\u7b54:<br \/>\n\u8981\u770b\u5177\u4f53\u4e1a\u52a1\u60c5\u51b5\uff0c\u5bf9\u5916\u90e8\u4e1a\u52a1\u4f9d\u8d56\u90fd\u5e94\u8be5\u914d\u7f6e,\u4f46API Gateway\u4e00\u5b9a\u662f\u914d\u7684\u6700\u5168\u7684<\/p>\n<p>27.\u8fd9\u4e2a\u8bfe\u7a0b\u4e3a\u4ec0\u4e48\u6709\u6ca1\u6709\u8bb2\u5230spring session<\/p>\n<p>\u7b54:<br \/>\n\u50cfSpringSession\u3001Spring Data Redis\u3001Spring Kafka\uff0c\u6211\u4eec\u751f\u4ea7\u73af\u5883\u90fd\u6ca1\u6709\u7528\uff0c\u4fb5\u5165\u6027\u592a\u5f3a\uff0c\u4e0d\u6613\u5b9a\u5236\u5316.<br \/>\n\u8bfe\u7a0b\u4e2d\u66f4\u5e0c\u671b\u5927\u5bb6\u80fd\u7406\u89e3\u89e3\u51b3\u65b9\u6848\u7684\u601d\u8def\u548c\u539f\u7406\uff0c\u800c\u4e0d\u662f\u65b9\u6848\u7684\u5957\u7528\uff0c\u5426\u5219\u65e0\u6cd5\u8fbe\u5230\u4e3e\u4e00\u53cd\u4e09\u7684\u76ee\u7684\uff0c\u5f15\u5165spring\u5f88\u591a\u6280\u672f\u6808\u4e5f\u4f1a\u5e26\u6765\u4e0d\u5c11\u7ef4\u62a4\u6210\u672c<\/p>\n<p>\u4f5c\u8005\uff1a \u683c_\u9c81<br \/>\n\u94fe\u63a5\uff1ahttps:\/\/www.imooc.com\/article\/23408<br \/>\n\u6765\u6e90\uff1a\u6155\u8bfe\u7f51<br \/>\n\u672c\u6587\u539f\u521b\u53d1\u5e03\u4e8e\u6155\u8bfe\u7f51 \uff0c\u8f6c\u8f7d\u8bf7\u6ce8\u660e\u51fa\u5904\uff0c\u8c22\u8c22\u5408\u4f5c<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u300aJava\u6df1\u5165\u5fae\u670d\u52a1\u539f\u7406\u6539\u9020\u623f\u4ea7\u9500\u552e\u5e73\u53f0\u300b\u5355\u4f53\u77e5\u8bc6\u70b9 \u4e00\u56fe\u80dc\u5343\u8a00 \u300aJava\u6df1\u5165\u5fae\u670d\u52a1\u539f\u7406\u6539\u9020\u623f\u4ea7\u9500\u552e\u5e73\u53f0\u300b\u5fae\u670d\u52a1\u77e5\u8bc6\u70b9 \u4e00\u56fe\u80dc\u5343\u8a00 \u300aJava\u6df1\u5165\u5fae\u670d\u52a1\u539f\u7406\u6539\u9020\u623f\u4ea7\u9500\u552e\u5e73\u53f0\u300b\u65e5\u5e38\u7b54\u7591 \u65e2\u7136\u5df2\u7ecf\u5728session\u6709\u4e86\uff0c\u76f4\u63a5session\u53d6\u5c31\u884c\u4e86\uff0c\u4e3a\u4ec0\u4e48\u8981\u518d\u653ethreadlocal\uff0c\u4e4b\u540e\u518d\u4ecethreadlocal\u6e05\u6389\uff0c\u4e00\u76f4\u4ecesession\u62ff\u4e0d\u5c31\u884c\u4e86\uff1f \u7b54: \u653e\u5728Threadlocal\u91cc\u9762\uff0c\u662f\u4e3a\u4e86\u540e\u9762\u7684Controller\u3001Service\u3001Dao\u4efb\u4f55\u5730\u65b9\u53ea\u8981\u662f\u5f53\u524d\u4e1a\u52a1\u5904\u7406\u7684\u7ebf\u7a0b\u90fd\u80fd \u76f4\u63a5\u5e76\u4e14\u65b9\u4fbf\u7684 \u83b7\u53d6\u5230\u7528\u6237\u5bf9\u8c61. \u5982\u679c\u6211\u4eec\u4e0d\u505a\u8fd9\u79cd\u5904\u7406\uff0c\u90a3\u53ea\u80fd\u4eceSession\u4e2d\u83b7\u53d6\uff0c\u5f53Service\u91cc\u9762\u8981\u83b7\u53d6user\u7684\u65f6\u5019\uff0cController\u5728\u8c03\u7528service\u65b9\u6cd5\u65f6\u5c31\u5fc5\u987b\u4f20\u9012HttpServletRequest\u8fd9\u79cd\u5bb9\u5668\u76f8\u5173\u53c2\u6570\uff0c\u589e\u52a0\u4e86\u4e1a\u52a1\u4e0e\u5e95\u5c42\u5b9e\u73b0\u7684\u8026\u5408\uff0c\u9020\u6210\u4e1a\u52a1\u5904\u7406\u5173\u6ce8\u70b9\u7684\u589e\u591a\uff1b\u800c\u4e14\u6bcf\u4e2aController\u90fd\u9700\u8981\u63a5\u6536HttpServletRequest\u53c2\u6570\uff0c\u56e0\u4e3a\u4e0d\u80fd\u9884\u4f30\u672a\u6765\u662f\u5426\u8981\u83b7\u53d6user\u5bf9\u8c61\u6765\u903b\u8f91\u5904\u7406\u3002 2 nginx\u7684\u914d\u7f6e\u4e2droot\u548calias\u7684\u533a\u522b\uff1f \u7b54: root\u548calias\u7684\u533a\u522b\u662f\u9171\u7d2b\u7684\uff1a \u914d\u7f6eroot\u9700\u8981\u8bbf\u95ee\u8def\u5f84\u8981\u53e0\u52a0\u76ee\u5f55\u8def\u5f84\uff0c\u6bd4\u5982\u914d\u7f6e\u4e86 location \/images { root [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[1],"tags":[],"class_list":["post-622","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/posts\/622","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=622"}],"version-history":[{"count":0,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/posts\/622\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=622"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=622"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=622"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}