{"id":40263,"date":"2023-12-07T04:21:29","date_gmt":"2023-08-01T08:05:52","guid":{"rendered":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8spring-boot-thymeleaf-tomcat-gradle%e5%bc%80%e5%8f%91%e4%b8%9a%e5%8a%a1%e5%ba%94%e7%94%a8%e6%97%b6%e7%9a%846%e4%b8%aa%e9%97%ae%e9%a2%98\/"},"modified":"2024-05-04T12:27:58","modified_gmt":"2024-05-04T04:27:58","slug":"%e4%bd%bf%e7%94%a8spring-boot-thymeleaf-tomcat-gradle%e5%bc%80%e5%8f%91%e4%b8%9a%e5%8a%a1%e5%ba%94%e7%94%a8%e6%97%b6%e7%9a%846%e4%b8%aa%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8spring-boot-thymeleaf-tomcat-gradle%e5%bc%80%e5%8f%91%e4%b8%9a%e5%8a%a1%e5%ba%94%e7%94%a8%e6%97%b6%e7%9a%846%e4%b8%aa%e9%97%ae%e9%a2%98\/","title":{"rendered":"\u4f7f\u7528Spring Boot + Thymeleaf + Tomcat + Gradle\u5f00\u53d1\u4e1a\u52a1\u5e94\u7528\u65f6\u76846\u4e2a\u95ee\u9898"},"content":{"rendered":"<p>\u6709\u8bb8\u591a\u6846\u67b6\u53ef\u4ee5\u6ee1\u8db3\u60f3\u8981\u7528Java\u5236\u4f5cWEB\u5e94\u7528\u7a0b\u5e8f\u7684\u9700\u6c42\uff0c\u4f46\u5176\u4e2dSpring Boot\u5728\u5176\u4e2d\u5177\u6709\u91cd\u8981\u7684\u5b58\u5728\u611f\u3002<br \/>\n\u7531\u4e8e\u6536\u5230\u4e86\u5e0c\u671b\u80fd\u5feb\u901f\u5efa\u7acb\u4e1a\u52a1\u5e94\u7528\u7a0b\u5e8f\u7684\u9700\u6c42\uff0c\u6240\u4ee5\u6211\u9009\u62e9\u4f7f\u7528\u4e86Spring Boot\u8fdb\u884c\u5f00\u53d1\u3002<br \/>\n\u7531\u4e8e\u9047\u5230\u4e86\u4e00\u4e9b\u95ee\u9898\uff0c\u6211\u505a\u4e86\u4e00\u4e9b\u7b14\u8bb0\uff0c\u73b0\u5728\u4e0e\u5927\u5bb6\u5206\u4eab\u4e00\u4e0b\u3002<\/p>\n<p>\u203b\u8bf7\u6ce8\u610f\uff1a\u4ee5\u4e0b\u5185\u5bb9\u662f\u4e3a\u4e86\u5206\u4eab\u4f7f\u7528\u8fc7\u7a0b\u4e2d\u9047\u5230\u7684\u56f0\u96be\u800c\u5199\u4e0b\u7684\u3002<br \/>\n\u203b\u5982\u679c\u60a8\u6ca1\u6709\u4f7f\u7528\u8fc7Spring Boot\uff0c\u6211\u8ba4\u4e3a\u8fd9\u7bc7\u6587\u7ae0\u53ef\u80fd\u4f1a\u5bf9\u60a8\u6709\u6240\u5e2e\u52a9\uff1ahttp:\/\/qiita.com\/opengl-8080\/items\/05d9490d6f0544e2351a<\/p>\n<h3>\u6574\u4e2a\u7cfb\u7edf\u7684\u7ed3\u6784<\/h3>\n<p>\u30fb\u6846\u67b6\uff1aSpring Boot<br \/>\n\u30fb\u8fd0\u884c\u73af\u5883\uff1a\u5f00\u53d1\u4e2d\u4f7f\u7528\u5185\u5d4cTomcat\u3002\u751f\u4ea7\u73af\u5883\u4f7f\u7528Tomcat7\u3002<br \/>\n\u30fb\u767b\u5f55\u8ba4\u8bc1\uff1aSpring Security<br \/>\n\u30fb\u8868\u793a\u5c42\uff1aThymeleaf\u3002\u4f7f\u7528Bootstrap + Flat UI\u6765\u7f8e\u5316\u754c\u9762\u3002<br \/>\n\u30fb\u8bed\u8a00\uff1aJava SE 8<br \/>\n\u30fb\u8fd0\u884c\u65f6\u5047\u8bbe\u4f7f\u7528HTTPS\u901a\u4fe1<br \/>\n\u30fb\u524d\u7aef\u4f7f\u7528Apache2.2<\/p>\n<p>\u7531\u4e8e\u5f00\u53d1\u56e2\u961f\u4e2d\u4f7f\u7528Eclipse\u7684\u7528\u6237\u8f83\u591a\uff0c\u6240\u4ee5\u9009\u62e9\u4e86Eclipse4.4\u7248\u672c\u3002\u5e76\u5b9a\u4e49\u4e86Checkstyle\u4e0eCodeFormatter\uff0c\u4f9b\u6240\u6709\u4eba\u5171\u4eab\u4f7f\u7528\u3002<\/p>\n<h2>\uff11\uff1a\u5b9a\u4e49\u5f00\u53d1\u73af\u5883\u633a\u9ebb\u70e6\u7684\u5462&#8230;<\/h2>\n<p>\u4f7f\u7528Spring Boot\u53ef\u4ee5\u4f7f\u7528gradle + application.properties\u51e0\u4e4e\u5b8c\u6210\u73af\u5883\u914d\u7f6e\u3002\u7136\u800c\uff0c\u4ece\u96f6\u5f00\u59cb\u6784\u5efa\u9700\u8981\u82b1\u8d39\u65f6\u95f4\uff0c\u56e0\u6b64\u6700\u597d\u5c3d\u91cf\u4eceSpring Boot\u5b98\u65b9\u7f51\u9875\u4e2d\u83b7\u53d6\u3002\u7136\u800c\uff0c\u6bcf\u4e00\u884c\u90fd\u6709\u610f\u4e49\uff0c\u6240\u4ee5\u4e0d\u80fd\u968f\u610f\u7ffb\u8bd1\u3002<\/p>\n<pre class=\"post-pre\"><code>\r\napply plugin: \"java\"\r\napply plugin: \"spring-boot\"\r\napply plugin: \"war\"\r\napply plugin: \"eclipse\"\r\n\r\ndescription = \"XXXXXXX\"\r\nwar {\r\n    baseName = \"XXXXXXX\"\r\n}\r\nconfigurations.all {\r\n    resolutionStrategy {\r\n        eachDependency {\r\n            if (it.requested.group == \"org.apache.tomcat.embed\") {\r\n                it.useVersion \"7.0.59\"\r\n            }\r\n        }\r\n    }\r\n}\r\nbuildscript {\r\n    repositories {\r\n        jcenter()\r\n        mavenCentral()\r\n    }\r\n    dependencies {\r\n        classpath \"org.springframework.boot:spring-boot-gradle-plugin:1.2.3.RELEASE\"\r\n        classpath \"org.springframework:springloaded:1.2.3.RELEASE\"\r\n    }\r\n}\r\nconfigurations {\r\n    providedRuntime\r\n}\r\ndependencies {\r\n    def springBootVersion=\"1.2.3.RELEASE\"\r\n    compile \"net.sf.dozer:dozer:5.5.1\"\r\n    compile \"org.springframework.boot:spring-boot-starter-data-jpa:${springBootVersion}\"\r\n    compile \"org.springframework.boot:spring-boot-starter-thymeleaf:${springBootVersion}\"\r\n    compile \"org.springframework.boot:spring-boot-starter-security:${springBootVersion}\"\r\n    compile \"org.thymeleaf.extras:thymeleaf-extras-springsecurity3:2.1.2.RELEASE\"\r\n    compile \"org.springframework.boot:spring-boot-starter-web:${springBootVersion}\"\r\n    providedRuntime \"org.springframework.boot:spring-boot-starter-tomcat:${springBootVersion}\" \r\n    testCompile \"org.springframework:spring-test\"\r\n    testCompile \"org.springframework.boot:spring-boot-starter-test:${springBootVersion}\"\r\n\r\n    \/\/\u3053\u3053\u306bjdbc\u3092\u5165\u308c\u3066\u306d\r\n\r\n}\r\n<\/code><\/pre>\n<p>\u5982\u679c\u5f00\u542f\u70ed\u90e8\u7f72\u529f\u80fd\uff0c\u5373\u4f7f\u5728\u8fd0\u884c\u65f6\u4e5f\u53ef\u4ee5\u8fdb\u884c\u91cd\u65b0\u52a0\u8f7d\u3002\u8fd9\u662f\u4e00\u4e2a\u5fc5\u5907\u529f\u80fd\u3002<\/p>\n<blockquote><p>org.springframework:springloaded:1.2.3.RELEASE \u53ef\u4ee5\u6539\u5199\u4e3a<\/p>\n<p>org.springframework:springloaded:1.2.3.RELEASE<\/p><\/blockquote>\n<p>\u30fbspring-boot-starter-tomcat \u662f\u5185\u7f6e\u7684 Tomcat\u3002\u5f00\u53d1\u8005\u53ef\u4ee5\u901a\u8fc7 Eclipse \u7684\u8fd0\u884c\u6309\u94ae\u542f\u52a8\u5e94\u7528\u7a0b\u5e8f\uff0c\u800c\u65e0\u9700\u5b89\u88c5 Tomcat\u3002\u7136\u800c\uff0c\u5728\u4f7f\u7528 Tomcat \u8fd0\u884c\u73af\u5883\u65f6\uff0c\u5185\u7f6e\u7684 Tomcat \u53ef\u80fd\u4f1a\u9020\u6210\u5e72\u6270\uff0c\u56e0\u6b64\u9700\u8981\u8fdb\u884c\u4ee5\u4e0b\u64cd\u4f5c\u3002<\/p>\n<blockquote><p>\u63d0\u4f9b\u8fd0\u884c\u65f6\u73af\u5883 &#8220;org.springframework.boot:spring-boot-starter-tomcat:${springBootVersion}&#8221;<\/p><\/blockquote>\n<p>\u5c06ConnectionPool\u7684\u7ba1\u7406\u4ea4\u7ed9Tomcat\u5904\u7406\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\u662f\/src\/main\/resources\/application.properties\u3002<\/p>\n<p>\u8bf7\u7ee7\u7eed\/src\/main\/resources\/application.properties\u3002<\/p>\n<pre class=\"post-pre\"><code>spring.datasource.url=jdbc:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\r\nspring.datasource.username=XXXX\r\nspring.datasource.password=XXXX\r\nspring.datasource.driverClassName=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\r\n#\u30b3\u30cd\u30af\u30b7\u30e7\u30f3\u30d7\u30fc\u30eb\u8a2d\u5b9a(default)\r\nspring.datasource.max-active=100\r\nspring.datasource.max-idle=8\r\nspring.datasource.min-idle=8\r\nspring.datasource.initial-size=10\r\n#\u30bb\u30c3\u30b7\u30e7\u30f3\u30bf\u30a4\u30e0\u30a2\u30a6\u30c8\u30921800\u79d2\u3068\u3059\u308b\u3002\r\nspring.datasource.session-timeout=1800\r\n#\u30b3\u30cd\u30af\u30b7\u30e7\u30f3\u3092\u5229\u7528\u3059\u308b\u969b\u306b\u691c\u8a3c\u3092\u884c\u3046\u3002DB\u304c\u518d\u8d77\u52d5\u3057\u3066\u3044\u3066\u3082\u3053\u306e\u51e6\u7406\u3092\u631f\u3080\u3053\u3068\u3067tomcat\u3092\u518d\u8d77\u52d5\u3057\u306a\u304f\u3066\u3082\u6e08\u3080\r\nspring.datasource.test-on-borrow=true\r\nspring.datasource.validation-query=SELECT 1\r\n#\u30b3\u30df\u30c3\u30c8\u3055\u308c\u305a\u306b\u6b8b\u3063\u305f\u30b3\u30cd\u30af\u30b7\u30e7\u30f3\u306f60\u79d2\u5f8c\u306b\u7834\u68c4\u3055\u308c\u308b\u3002\r\nspring.datasource.remove-abandoned=true\r\nspring.datasource.remove-abandoned-timeout=60\r\nspring.thymeleaf.prefix=classpath:\/templates\/\r\nspring.thymeleaf.suffix=.html\r\nspring.thymeleaf.mode=HTML5\r\nspring.thymeleaf.encoding=UTF-8\r\nspring.thymeleaf.content-type=text\/html\r\nspring.thymeleaf.cache=false\r\nserver.session-timeout=1800\r\nserver.context-path=\/XXXXXXXX\r\nspring.messages.cache-seconds=-1\r\nerror.whitelabel.enabled=false\r\nsecurity.require_ssl=true\r\n<\/code><\/pre>\n<p>\u6700\u597d\u662f\u63d0\u524d\u5b9a\u4e49 server.context\uff0c\u8fd9\u6837\u4f1a\u66f4\u8f7b\u677e\u3002\u6211\u5728\u6570\u636e\u5e93\u65b9\u9762\u9047\u5230\u4e86\u4e00\u4e9b\u56f0\u60d1\u3002\u6211\u8fdb\u884c\u4e86\u591a\u6b21\u6d4b\u8bd5\uff0c\u5173\u95ed\u548c\u91cd\u65b0\u542f\u52a8\u6570\u636e\u5e93\uff0c\u6700\u7ec8\u5f97\u5230\u4e86\u8fd9\u4e2a\u7ed3\u8bba\u3002<\/p>\n<h2>2\uff1a\u5f53\u4f1a\u8bdd\u8d85\u65f6\u65f6\u8be5\u600e\u4e48\u529e\uff1f<\/h2>\n<p>\u4e3a\u4ec0\u4e48\u4e1a\u52a1\u7cfb\u7edf\u8981\u91cd\u89c6\u4f1a\u8bdd\u8d85\u65f6\uff1f\u867d\u7136\u53ef\u4ee5\u6dfb\u52a0\uff0c\u4f46\u5b9e\u9645\u5b9e\u65bd\u590d\u6742\u3002<\/p>\n<p>\u5728\u8d85\u65f6\u60c5\u51b5\u4e0b\uff0c\u6709\u4e24\u79cd\u6a21\u5f0f\u3002<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u5728\u8d85\u65f6\u540e\u5c1d\u8bd5\u8fdb\u884c\u9875\u9762\u8df3\u8f6c\u65f6\uff1a<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u5982\u679c\u53d1\u751f\u4e86\u4f1a\u8bdd\u8d85\u65f6\uff0c\u4f1a\u8df3\u8f6c\u5230\u767b\u5f55\u9875\u9762\uff0c\u5e76\u663e\u793a\u6d88\u606f\uff1a\u201c\u4f1a\u8bdd\u5df2\u8d85\u65f6\u201d\u3002<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u4f46\u662f\uff0c\u767b\u5f55\u9875\u9762\u548c\u767b\u51fa\u9875\u9762\u4e0d\u53d7\u4f1a\u8bdd\u8d85\u65f6\u7684\u5f71\u54cd\u3002<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u5728\u8d85\u65f6\u540e\u5c1d\u8bd5\u8fdb\u884cAjax\u901a\u4fe1\u65f6\uff1a<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u4e13\u95e8\u7528\u4e8eAjax\u7684\u5171\u4eab\u54cd\u5e94\u6a21\u578b\uff0c\u5728\u4efb\u4f55\u9875\u9762\u4e2d\u90fd\u8fd4\u56de\u6b64\u54cd\u5e94\u6a21\u578b\u3002<\/ol>\n<pre class=\"post-pre\"><code>\r\n    private boolean success = false;\r\n    private List&lt;String&gt; messages = new ArrayList&lt;&gt;();\r\n    private Object data;\r\n+ getter \/ setter\r\n<\/code><\/pre>\n<p>\u53ea\u8981\u5728\u6240\u6709API\u4e2d\u90fd\u8fd4\u56de\u8fd9\u4e2a\u6a21\u578b\uff0c\u5c31\u53ef\u4ee5\u8fd4\u56de\u8d85\u65f6\u6d88\u606f\uff08\u5e76\u4e14\u53ef\u80fd\u4f1a\u5728\u6a21\u6001\u6846\u4e2d\u663e\u793a\uff09\u3002<\/p>\n<p>\u597d\u7684\uff0c\u8ba9\u6211\u4eec\u5f00\u59cb\u5b9e\u73b0\u3002<br \/>\n\u5728\u4e00\u4e2a\u62e6\u622a\u5668\u4e2d\u5199\u4e0b\u4ee5\u4e0b\u4ee3\u7801\u3002\u4ee3\u7801\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n<pre class=\"post-pre\"><code>\/**\r\n * \u30bb\u30c3\u30b7\u30e7\u30f3\u30bf\u30a4\u30e0\u30a2\u30a6\u30c8\u6642\u306e\u6319\u52d5\u3092\u5b9a\u7fa9\u3059\u308b\u3002\r\n *\/\r\npublic class SessionExpireInterceptor implements HandlerInterceptor {\r\n    @Override\r\n    public boolean preHandle(HttpServletRequest request, HttpServletResponse response,\r\n            Object handler) throws Exception {\r\n        if (isTarget(request)) {\r\n            \/\/ \u30bb\u30c3\u30b7\u30e7\u30f3\u30bf\u30a4\u30e0\u30a2\u30a6\u30c8\u306e\u30c1\u30a7\u30c3\u30af\r\n            if (isSessionTimeout(request)) { \/\/ \u30bb\u30c3\u30b7\u30e7\u30f3\u30bf\u30a4\u30e0\u30a2\u30a6\u30c8\u306e\u5834\u5408\r\n                \/\/ Ajax\u51e6\u7406\u306e\u5834\u5408\u306f\u300c\u30bb\u30c3\u30b7\u30e7\u30f3\u30bf\u30a4\u30e0\u30a2\u30a6\u30c8\u304c\u767a\u751f\u3057\u307e\u3057\u305f\u3002\u30ed\u30b0\u30a4\u30f3\u3057\u306a\u304a\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u300d\u3068\u3044\u3046\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u8fd4\u5374\u3059\u308b\u3002\r\n                if (isAjaxRequest(request)) {\r\n                    String message =\r\n                            \"{\\\"success\\\":false,\\\"messages\\\":[\\\"\u30bb\u30c3\u30b7\u30e7\u30f3\u30bf\u30a4\u30e0\u30a2\u30a6\u30c8\u304c\u767a\u751f\u3057\u307e\u3057\u305f\u3002\u30ed\u30b0\u30a4\u30f3\u3057\u306a\u304a\u3057\u3066\u304f\u3060\u3055\u3044\u3002\\\"]}\";\r\n                    response.setContentType(\"text\/html;charset=UTF-8\");\r\n                    \/\/ \u30b9\u30c6\u30fc\u30bf\u30b9\u306f200\u3068\u306a\u308b\u304c\u3001success = false\u3068\u3059\u308b\u3002\r\n                    response.setStatus(HttpServletResponse.SC_OK);\r\n                    response.getWriter().write(message);\r\n                    return false;\r\n                } else {\r\n                    String requestUri = request.getRequestURI();\r\n                    \/\/ \u30ed\u30b0\u30a4\u30f3\u30fb\u30ed\u30b0\u30a2\u30a6\u30c8\u30fb\u30bf\u30a4\u30e0\u30a2\u30a6\u30c8\u30da\u30fc\u30b8\u306e\u30bf\u30a4\u30e0\u30a2\u30a6\u30c8\u306f\u884c\u308f\u306a\u3044\u3002\r\n                    if (!((request.getContextPath() + AppConst.URL_LOGIN_PAGE + \"\/timeout\")\r\n                            .equals(requestUri) \/\/\r\n                            || (request.getContextPath() + AppConst.URL_LOGIN_PAGE)\r\n                                    .equals(requestUri) \/\/\r\n                    || (request.getContextPath() + AppConst.URL_LOGOUT_COMPLETED_PAGE)\r\n                            .equals(requestUri))) {\r\n                        \/\/ \u901a\u5e38\u753b\u9762\u306e\u5834\u5408\u306f\u3001\u30ed\u30b0\u30a4\u30f3\u753b\u9762\u3092\u8868\u793a\u3057\u30bb\u30c3\u30b7\u30e7\u30f3\u30bf\u30a4\u30e0\u30a2\u30a6\u30c8\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u4f1d\u3048\u308b\u3002\r\n                        response.sendRedirect(request.getContextPath() + AppConst.URL_LOGIN_PAGE\r\n                                + \"\/timeout\");\r\n                    }\r\n                }\r\n            }\r\n        }\r\n        return true;\r\n    }\r\n    \/**\r\n     * \u5bfe\u8c61\u306e\u30ea\u30af\u30a8\u30b9\u30c8\u304b\u5224\u5b9a\r\n     * css, js, favicon\u7b49\u306e\u30ea\u30bd\u30fc\u30b9\u30a2\u30af\u30bb\u30b9\u306b\u3064\u3044\u3066\u306f\u51fa\u529b\u5bfe\u8c61\u5916\r\n     *\r\n     * @param request \u30ea\u30af\u30a8\u30b9\u30c8\r\n     * @return true : \u30ed\u30ae\u30f3\u30b0\u5bfe\u8c61 \/ false : \u30ed\u30ae\u30f3\u30b0\u5bfe\u8c61\u3067\u306f\u306a\u3044\r\n     *\/\r\n    private boolean isTarget(ServletRequest request) {\r\n        String uri = ((HttpServletRequest) request).getRequestURI();\r\n        return (uri.indexOf(\"\/static\") &lt; 0 &amp;&amp; uri.indexOf(\"\/favicon.ico\") &lt; 0);\r\n    }\r\n    \/**\r\n     * Ajax\u30ea\u30af\u30a8\u30b9\u30c8\u5224\u5b9a\r\n     *\r\n     * @param request \u30ea\u30af\u30a8\u30b9\u30c8\r\n     * @return true : Ajax\u30ea\u30af\u30a8\u30b9\u30c8 \/ false : \u305d\u3046\u3067\u306f\u306a\u3044\r\n     *\/\r\n    private boolean isAjaxRequest(ServletRequest request) {\r\n        return StringUtils.equals(\"XMLHttpRequest\",\r\n                ((HttpServletRequest) request).getHeader(\"X-Requested-With\"));\r\n    }\r\n    \/**\r\n     * \u30bb\u30c3\u30b7\u30e7\u30f3\u30bf\u30a4\u30e0\u30a2\u30a6\u30c8\u5224\u5b9a\r\n     *\r\n     * @param request\r\n     * @return\r\n     *\/\r\n    private boolean isSessionTimeout(HttpServletRequest request) {\r\n        HttpSession falsecurrentSession = request.getSession(false);\r\n        if (falsecurrentSession == null) {\r\n            return true;\r\n        }\r\n        String requestSession = request.getRequestedSessionId();\r\n        boolean isValid = request.isRequestedSessionIdValid();\r\n        return falsecurrentSession == null || requestSession == null || !isValid\r\n                || !requestSession.equals(falsecurrentSession.getId());\r\n    }\r\n    @Override\r\n    public void postHandle(HttpServletRequest request, HttpServletResponse response,\r\n            Object handler, ModelAndView modelAndView) throws Exception {}\r\n    @Override\r\n    public void afterCompletion(HttpServletRequest request, HttpServletResponse response,\r\n            Object handler, Exception ex) throws Exception {}\r\n}\r\n<\/code><\/pre>\n<h2>\u4f7f\u7528Spring Security\u4e3a\u4e00\u4e2a\u7528\u6237\u5206\u914d\u591a\u4e2a\u6743\u9650\u7684\u65b9\u6cd5<\/h2>\n<p>\u5f15\u5165\u4e86\u80fd\u591f\u5904\u7406\u767b\u5f55\u9a8c\u8bc1\u7684Spring Security\u3002\u672c\u6b21\u89c4\u5219\u5982\u4e0b\u3002<\/p>\n<p>\u00b7 \u6bcf\u4e2a\u7528\u6237\u53ea\u80fd\u62e5\u6709\u4e00\u4e2a\u89d2\u8272\u3002<br \/>\n\u00b7 \u6bcf\u4e2a\u89d2\u8272\u53ef\u4ee5\u62e5\u6709\u591a\u4e2a\u6743\u9650\u3002<br \/>\n\u00b7 \u89d2\u8272\u793a\u4f8b: &#8220;\u7ba1\u7406\u5458&#8221;, &#8220;\u64cd\u4f5c\u5458&#8221;, &#8220;\u666e\u901a\u7528\u6237&#8221;\u3002<br \/>\n\u00b7 \u6743\u9650\u793a\u4f8b: \u529f\u80fdA_\u53ea\u8bfb\u6743\u9650\/\u529f\u80fdA_\u66f4\u65b0\u6743\u9650\/\u529f\u80fdB_\u53ea\u8bfb\u6743\u9650\/\u529f\u80fdB_\u66f4\u65b0\u6743\u9650\u3002<br \/>\n\u00b7 \u7528\u6237\u767b\u5f55\u540e\uff0c\u5982\u679c\u6ca1\u6709\u6743\u9650\uff0c\u5c06\u4e0d\u4f1a\u663e\u793a\u6253\u5f00\u8be5\u9875\u9762\u7684\u6309\u94ae\u3002\u76f4\u63a5\u8f93\u5165URL\u4e5f\u4f1a\u663e\u793a\u6743\u9650\u9519\u8bef\u3002<\/p>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d3f9037434c4406c8f378\/27-0.jpeg\" alt=\"2015y10m18d_160505348.jpg\" \/><\/div>\n<p>\u4ee3\u7801\u6a2a\u8de8\u591a\u4e2a\u7c7b\uff0c\u4f46\u53ea\u9700\u8981\u62bd\u53d6\u90e8\u5206\u5185\u5bb9\u3002<\/p>\n<pre class=\"post-pre\"><code> \/**\r\n * \u8a8d\u8a3c\u51e6\u7406\u3092\u5b9f\u65bd\u3059\u308b\u30af\u30e9\u30b9\r\n *\/\r\n@Service\r\npublic class UserDetailLogic implements UserDetailsService {\r\n    @Autowired\r\n    UserLogic userLogic;\r\n    private Logger logger = LoggerFactory.getLogger(UserDetailLogic.class);\r\n    @Override\r\n    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {\r\n        \/\/ \u30e6\u30fc\u30b6\u60c5\u5831\u53d6\u5f97\r\n        MUser mUser = userLogic.findUserByUserId(username);\r\n        if (mUser == null) {\r\n            String errorMessage = **********************************************\r\n            logger.info(errorMessage);\r\n            throw new UsernameNotFoundException(errorMessage);\r\n        }\r\n        \/\/ \u6a29\u9650\u3092\u30bb\u30c3\u30c8\u3059\u308b\u3002\r\n        List&lt;SimpleGrantedAuthority&gt; authorityList = new ArrayList&lt;SimpleGrantedAuthority&gt;();\r\n        \/\/ \u6a29\u9650\u53d6\u5f97\r\n        List&lt;MRRoleAuthority&gt; auths = userLogic.getAuthorities(mUser.getRoleId());\r\n        for (MRRoleAuthority auth : auths) {\r\n            authorityList.add(new SimpleGrantedAuthority(auth.getId().getAuthorityName()));\r\n        }\r\n        return new UserDetail(mUser, authorityList);\r\n    }\r\n}\r\n<\/code><\/pre>\n<p>\u5982\u679c\u63a7\u5236\u5668\u4e0a\u5199\u4e0a\u4ee5\u4e0b\u5185\u5bb9\uff0c\u90a3\u4e48\u5f53\u6ca1\u6709\u6743\u9650\u7684\u7528\u6237\u5230\u6765\u65f6\uff0c\u53ef\u4ee5\u5c06\u5176\u8f6c\u81f3403\u9519\u8bef\u9875\u9762\u3002<\/p>\n<pre class=\"post-pre\"><code>@PreAuthorize(\"hasRole('SELECT_ZYX')\") \/\/ ZYX\u306e\u53c2\u7167\u6a29\u304c\u5fc5\u8981\r\n@RequestMapping(value = \"\/\")\r\npublic String index(Model model) {\r\n  ....\r\n}\r\n<\/code><\/pre>\n<p>\u5982\u679c\u5728\u9875\u9762\u4e0a\u6309\u7167\u4ee5\u4e0b\u65b9\u5f0f\u7f16\u5199\uff0c\u53ea\u6709\u5728\u5177\u5907\u6743\u9650\u65f6\u624d\u4f1a\u521b\u5efa\u53ef\u89c1\u7684\u6309\u94ae\u3002<\/p>\n<pre class=\"post-pre\"><code>&lt;li sec:authorize=\"hasRole('SELECT_ZYX')\"&gt;&lt;a th:href=\"@{\/sites\/}\"&gt;ZYX\u6a5f\u80fd&lt;\/a&gt;&lt;\/li&gt;\r\n<\/code><\/pre>\n<h2>4\uff1a\u4f60\u662f\u600e\u4e48\u8fdb\u884c\u9a8c\u8bc1\u7684\uff1f<\/h2>\n<p>\u5ba2\u6237\u7aef\u9a8c\u8bc1\u5df2\u8fdb\u884c\u81ea\u5b9a\u4e49\u5b9e\u73b0\u3002\u901a\u8fc7\u8c03\u7528Validator.checkRule(&#8220;\u57df\u89c4\u5219\u540d\u79f0&#8221;, \u503c)\uff0c\u53ef\u4ee5\u8fd4\u56de\u76f8\u5e94\u7684\u6d88\u606f\u5b9e\u73b0\u3002<br \/>\n\u5c06\u6d88\u606f\u5b58\u50a8\u5728messages\u4e2d\uff0c\u5e76\u5728\u6709\u6d88\u606f\u65f6\u663e\u793a\u9519\u8bef\u6a21\u6001\u6846\u3002<\/p>\n<pre class=\"post-pre\"><code>messages.push({\r\n    message: Validator.checkRule(\"NAME_255\", $(\"#zyxName\").val()),\r\n    arg: \"\u540d\u79f0\"\r\n});\r\nmessages.push({\r\n    message: Validator.checkRule(\"ID_8\", $(\"#zyxId\").val()),\r\n    arg: \"ID\"\r\n});\r\nmessages.push({\r\n    message: Validator.checkRule(\"URL\", $(\"#zyxUrl\").val()),\r\n    arg: \"URL\"\r\n});\r\n<\/code><\/pre>\n<p>\u670d\u52a1\u5668\u7aef\u9a8c\u8bc1\u91c7\u7528\u4e86@BindingResult\u3002\u53ea\u9700\u5c06@Length(max = 10)\u6216@Pattern(regexp=\u6b63\u5219\u8868\u8fbe\u5f0f)\u7b49\u9a8c\u8bc1\u89c4\u5219\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u7ed9\u6a21\u578b\u5bf9\u8c61\u7684\u5b57\u6bb5\uff0c\u53ef\u4ee5\u8f7b\u677e\u5730\u7f16\u5199\u9a8c\u8bc1\u89c4\u5219\u3002<\/p>\n<pre class=\"post-pre\"><code>@Pattern(regexp = ValidationConst.PATTERN_URL_POLICY,\r\n        message = ValidationConst.ERROR_MESSAGE_MATCH)\r\n@Length(max = ValidationConst.VALIDATION_RULE_URL,\r\n        message = ValidationConst.ERROR_MESSAGE_MAXSIZE)\r\nprivate String url = \"\";\r\n<\/code><\/pre>\n<p>\u7528\u63a5\u6536\u5668\u5c06\u6d88\u606f\u8f6c\u6362\u5e76\u8fd4\u56de\u5230\u5c4f\u5e55\u3002<\/p>\n<pre class=\"post-pre\"><code>@PreAuthorize(\"hasRole('UPDATE_ZYX')\")\r\n@RequestMapping(value = \"\/entry\", method = RequestMethod.POST)\r\n@ResponseBody\r\npublic CommonResultModel executeEntry(@RequestBody @Valid ZyxModel zxyInfoForm,\r\n        BindingResult bindingResult) {\r\n    CommonResultModel result = new CommonResultModel();\r\n    \/\/ parameter check result has error -&gt; return error messages\r\n    if (bindingResult.hasErrors()) {\r\n        for (FieldError fe : bindingResult.getFieldErrors()) {\r\n            result.addMessage(fe.getDefaultMessage(), fe.getField(), fe.getRejectedValue());\r\n        }\r\n        logger.warn(result.getMessages().toString()); \/\/ server side validation -&gt; warn\r\n        return result;\r\n    }\r\n<\/code><\/pre>\n<h2>\u8ba9\u6211\u4eec\u4f7f\u7528\u5171\u540c\u7684\u65e5\u5fd7\u8bb0\u5f55\u3002<\/h2>\n<p>\u6709\u4e9b\u9879\u76ee\u8981\u6c42\u6bcf\u6b21\u5728\u5e94\u7528\u7a0b\u5e8f\u4e2d\u8bb0\u5f55\u7c7b\u4f3c\u4e8e\u201c\u5df2\u5f00\u59cb\u25cb\u25cb\u3002\u7528\u6237\u540d\uff1ahoge\u201d\u548c\u201c\u5df2\u7ed3\u675f\u00d7\u00d7\u3002\u53c2\u6570\uff1abar=foo\u201d\u8fd9\u6837\u7684\u65e5\u5fd7\u3002\u7531\u4e8e\u6e05\u695a\u5730\u663e\u793a\u4e86\u54ea\u4e2a\u7528\u6237\u8fdb\u884c\u4e86\u4ec0\u4e48\u64cd\u4f5c\uff0c\u6240\u4ee5\u6211\u5f88\u559c\u6b22\u3002\u8fd9\u6b21\u6211\u4f7f\u7528\u4e86\u8fc7\u6ee4\u5668\u6765\u8bb0\u5f55\u201c\u54ea\u4e2a\u7528\u6237\u8fdb\u884c\u4e86\u4ec0\u4e48\u64cd\u4f5c\uff1f\u201d\u7684\u65e5\u5fd7\u8f93\u51fa\uff0c\u5e76\u7528\u8fc7\u6ee4\u5668\u8fdb\u884c\u4e86\u63cf\u8ff0\u3002<\/p>\n<pre class=\"post-pre\"><code>@Override\r\n public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)\r\n         throws IOException, ServletException {\r\n     \/\/ HTTP\u30ea\u30af\u30a8\u30b9\u30c8\u306e\u5834\u5408\u3001\u51e6\u7406\u958b\u59cb\u30ed\u30b0\u3092\u51fa\u529b\r\n     if (request instanceof HttpServletRequest) {\r\n         String uri = ((HttpServletRequest) request).getRequestURI();\r\n         String method = ((HttpServletRequest) request).getMethod();\r\n         \/\/ \u958b\u59cb\u30ed\u30ae\u30f3\u30b0\u5bfe\u8c61\u306e\u30a2\u30af\u30bb\u30b9\u306e\u5834\u5408\u306f\u30ed\u30b0\u51fa\u529b\r\n         if (isStartLoggingTarget(request)) {\r\n             String messageCode = getProcessStartMessageCode(request);\r\n             String userId = getUserIdFromSession(request);\r\n             logger.info(MessageUtil.make(messageCode, userId, method, uri));\r\n         }\r\n     }\r\n     \/\/ \u5b9f\u51e6\u7406\u5b9f\u65bd\r\n     chain.doFilter(request, response);\r\n     \/\/ HTTP\u30ea\u30af\u30a8\u30b9\u30c8\u306e\u5834\u5408\u3001\u51e6\u7406\u7d42\u4e86\u30ed\u30b0\u3092\u51fa\u529b\r\n     if (request instanceof HttpServletRequest) {\r\n         String uri = ((HttpServletRequest) request).getRequestURI();\r\n         String method = ((HttpServletRequest) request).getMethod();\r\n         \/\/ \u7d42\u4e86\u30ed\u30ae\u30f3\u30b0\u5bfe\u8c61\u306e\u30a2\u30af\u30bb\u30b9\u306e\u5834\u5408\u306f\u30ed\u30b0\u51fa\u529b\r\n         if (isEndLoggingTarget(request)) {\r\n             String messageCode = MessageUtil.MC_COMMON_API_END;\r\n             String userId = getUserIdFromSession(request);\r\n             logger.info(MessageUtil.make(messageCode, userId, method, uri));\r\n         }\r\n     }\r\n }\r\n<\/code><\/pre>\n<p>\u63d0\u524d\u786e\u5b9a\u65e5\u5fd7\u8f93\u51fa\u7b56\u7565\u3002\u5fc5\u987b\u8fdb\u884c\u5e94\u7528\u7a0b\u5e8f\u5f00\u53d1\u548c\u7ba1\u7406\uff08\u76d1\u63a7\uff09\u4eba\u5458\u4ee5\u53ca\u65e5\u5fd7\u6587\u4ef6\u7684\u8f6e\u8f6c\u7684\u534f\u5546\u3002<\/p>\n<h2>\u4f7f\u7528SpringSecurity\u521b\u5efa\u767b\u5f55\u9875\u9762\u3002\u5728HTTP\u901a\u4fe1\u4e2d\u6ca1\u6709\u95ee\u9898\uff0c\u4f46\u5728\u4f7f\u7528HTTPS\u901a\u4fe1\u65f6\uff0c\u767b\u5f55\u540e\u7684URL\u4f1a\u51fa\u73b0\u5f02\u5e38\u3002<\/h2>\n<p>\u5177\u4f53\u6765\u8bf4\uff0c\u60c5\u51b5\u662f\u8fd9\u6837\u7684\u3002<br \/>\nhttps:\/\/example.com:80\/app1\/logined<br \/>\n\u867d\u7136\u4f7f\u7528\u4e86https\uff0c\u4f46\u5374\u8bd5\u56fe\u8fde\u63a5\u523080\u7aef\u53e3\u3002<\/p>\n<p>\u5982\u679c\u5c06\u5176\u4ea4\u7ed9SpringSecurity\u5904\u7406\uff0c\u767b\u5f55\u540e\u7684URL\u5c06\u88ab\u91cd\u5b9a\u5411\u3002<br \/>\n\u5728Tomcat\u7684server.xml\u4e2d\uff0c\u5c06proxyPort\u5b9a\u4e49\u4e3a443\u3002<\/p>\n<pre class=\"post-pre\"><code>&lt;!-- Define an AJP 1.3 Connector on port 8009 --&gt;\r\n&lt;Connector port=\"8009\" protocol=\"AJP\/1.3\" redirectPort=\"8443\" proxyPort=\"443\" scheme=\"https\" secure=\"true\"\/&gt;\r\n<\/code><\/pre>\n<h2>\u5916\u4f20<\/h2>\n<p>\u51cf\u5c11\u5de5\u4f5c\u91cf\uff01\u51cf\u5c11\u5de5\u4f5c\u91cf\uff01\u5728\u4e00\u77ac\u4e4b\u95f4\u5206\u795e\u65f6\uff0c\u4e0d\u77e5\u600e\u5730\u5c31\u53d8\u6210\u4e86\u4e0d\u5236\u9020403\/404\/500\u7684\u65b9\u9488\u3002\u4f46\u6700\u7ec8\u8fd8\u662f\u4e0d\u5f97\u4e0d\u5236\u9020\u3002\u8981\u597d\u597d\u5b89\u6392\u5de5\u4f5c\u91cf\u3002\u5f88\u7b80\u5355\u3002<\/p>\n<pre class=\"post-pre\"><code>\/**\r\n * ServletContainerCustomizer\r\n *\r\n * @return\r\n *\/\r\n@Bean\r\npublic EmbeddedServletContainerCustomizer containerCustomizer() {\r\n    return new ServletContainerCustomizer();\r\n}\r\nprivate static class ServletContainerCustomizer implements EmbeddedServletContainerCustomizer {\r\n    @Override\r\n    public void customize(ConfigurableEmbeddedServletContainer factory) {\r\n        factory.addErrorPages(new ErrorPage(HttpStatus.FORBIDDEN, \"\/403\"));\r\n        factory.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, \"\/404\"));\r\n        factory.addErrorPages(new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, \"\/500\"));\r\n    }\r\n}\r\n\/**\r\n * 403\u30a8\u30e9\u30fc\u753b\u9762\u8868\u793a\r\n *\r\n * @return\r\n *\/\r\n@RequestMapping(\"\/403\")\r\npublic String forbiddenError() {\r\n    return \"error\/403\";\r\n}\r\n\/**\r\n * 404\u30a8\u30e9\u30fc\u753b\u9762\u8868\u793a\r\n *\r\n * @return\r\n *\/\r\n@RequestMapping(\"\/404\")\r\npublic String notFoundError() {\r\n    return \"error\/404\";\r\n}\r\n\/**\r\n * 500\u30a8\u30e9\u30fc\u753b\u9762\u8868\u793a\r\n *\r\n * @return\r\n *\/\r\n@RequestMapping(\"\/500\")\r\npublic String internalServerError() {\r\n    return \"error\/500\";\r\n}\r\n<\/code><\/pre>\n<p>\u5982\u679c\u51c6\u5907\u597d{\u9879\u76ee\u6839\u76ee\u5f55}\/src\/main\/resources\/template\/error\/500.html\u7b49\uff0c\u5b83\u4f1a\u5728\u51fa\u9519\u65f6\u663e\u793a\u51fa\u6765\u3002<\/p>\n<h2>\u5c1d\u8bd5\u4f7f\u7528SpringBoot&#8230;<\/h2>\n<p>\u8fd9\u4e2a\u5730\u65b9\u5f88\u597d\uff1a\u5373\u4f7f\u4e0d\u5b89\u88c5Tomcat\u4e5f\u53ef\u4ee5\u8fd0\u884c\uff0c\u975e\u5e38\u65b9\u4fbf\u3002\u73af\u5883\u914d\u7f6e\u51e0\u4e4e\u53ef\u4ee5\u901a\u8fc7gradle + application.properties\u5b8c\u6210\u3002<\/p>\n<p>\u4e0d\u8db3\u4e4b\u5904\uff1a\u6587\u6863\u91cf\u5c11\u3002\u7eca\u5012\u7684\u5730\u65b9\u5f88\u591a\u3002\u6ca1\u6709\u5171\u4eab\u7eca\u5012\u7684\u5730\u65b9\u3002\u6d4b\u8bd5\u4ee3\u7801\u542f\u52a8\u7f13\u6162\u3002\u9700\u8981\u82b1\u8d39\u65f6\u95f4\u9002\u5e94\u6d4b\u8bd5\u3002\u57fa\u672c\u4e0a\u4e0d\u8003\u8651\u4ecb\u7ecdSpring 3\u4e4b\u524d\u7684\u9875\u9762\u3002<br \/>\n\u4ecb\u7ecd\u4e86\u4f7f\u7528XML\u7f16\u5199\u7684\u65b9\u6cd5\uff0c\u4f46\u4e0d\u77e5\u9053\u5982\u4f55\u7528Java\u91cd\u65b0\u7f16\u5199\u3002<br \/>\nSpring\u76f8\u5173\u529f\u80fd\u8fc7\u4e8e\u4e30\u5bcc\uff0c\u4e0d\u77e5\u9053\u4ece\u54ea\u91cc\u5f00\u59cb\u505a\u8d77\uff0c\u5f88\u56f0\u60d1\u3002<\/p>\n<p>\u6625\u5929\u672c\u8eab\u53d8\u5f97\u591a\u529f\u80fd\u4e14\u590d\u6742\u5316\uff0c\u56e0\u6b64\u51fa\u73b0\u4e86\u53ef\u4ee5\u7ec4\u5408SpringBoot\u7ec4\u4ef6\u7684\u529f\u80fd\u3002\u4f46\u4e0eDjango\u3001Rails\u7b49\u5168\u6808\u6846\u67b6\u76f8\u6bd4\uff0c\u5b83\u66f4\u52a0\u81c3\u80bf\u4e14\u96be\u4ee5\u5904\u7406\u3002\u4f46\u662f\uff0c\u5982\u679c\u662fJava\u9879\u76ee\uff0c\u8fd9\u4f3c\u4e4e\u662f\u552f\u4e00\u7684\u9009\u62e9&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6709\u8bb8\u591a\u6846\u67b6\u53ef\u4ee5\u6ee1\u8db3\u60f3\u8981\u7528Java\u5236\u4f5cWEB\u5e94\u7528\u7a0b\u5e8f\u7684\u9700\u6c42\uff0c\u4f46\u5176\u4e2dSpring Boot\u5728\u5176\u4e2d\u5177\u6709\u91cd\u8981\u7684\u5b58\u5728\u611f\u3002 [&hellip;]<\/p>\n","protected":false},"author":9,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-40263","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u4f7f\u7528Spring Boot + Thymeleaf + Tomcat + Gradle\u5f00\u53d1\u4e1a\u52a1\u5e94\u7528\u65f6\u76846\u4e2a\u95ee\u9898 - Blog - Silicon Cloud<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.silicloud.com\/zh\/blog\/\u4f7f\u7528spring-boot-thymeleaf-tomcat-gradle\u5f00\u53d1\u4e1a\u52a1\u5e94\u7528\u65f6\u76846\u4e2a\u95ee\u9898\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u4f7f\u7528Spring Boot + Thymeleaf + Tomcat + Gradle\u5f00\u53d1\u4e1a\u52a1\u5e94\u7528\u65f6\u76846\u4e2a\u95ee\u9898\" \/>\n<meta property=\"og:description\" content=\"\u6709\u8bb8\u591a\u6846\u67b6\u53ef\u4ee5\u6ee1\u8db3\u60f3\u8981\u7528Java\u5236\u4f5cWEB\u5e94\u7528\u7a0b\u5e8f\u7684\u9700\u6c42\uff0c\u4f46\u5176\u4e2dSpring Boot\u5728\u5176\u4e2d\u5177\u6709\u91cd\u8981\u7684\u5b58\u5728\u611f\u3002 [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/zh\/blog\/\u4f7f\u7528spring-boot-thymeleaf-tomcat-gradle\u5f00\u53d1\u4e1a\u52a1\u5e94\u7528\u65f6\u76846\u4e2a\u95ee\u9898\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:published_time\" content=\"2023-08-01T08:05:52+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-05-04T04:27:58+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d3f9037434c4406c8f378\/27-0.jpeg\" \/>\n<meta name=\"author\" content=\"\u6e05, \u626c\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u6e05, \u626c\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8spring-boot-thymeleaf-tomcat-gradle%e5%bc%80%e5%8f%91%e4%b8%9a%e5%8a%a1%e5%ba%94%e7%94%a8%e6%97%b6%e7%9a%846%e4%b8%aa%e9%97%ae%e9%a2%98\/\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8spring-boot-thymeleaf-tomcat-gradle%e5%bc%80%e5%8f%91%e4%b8%9a%e5%8a%a1%e5%ba%94%e7%94%a8%e6%97%b6%e7%9a%846%e4%b8%aa%e9%97%ae%e9%a2%98\/\",\"name\":\"\u4f7f\u7528Spring Boot + Thymeleaf + Tomcat + Gradle\u5f00\u53d1\u4e1a\u52a1\u5e94\u7528\u65f6\u76846\u4e2a\u95ee\u9898 - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\"},\"datePublished\":\"2023-08-01T08:05:52+00:00\",\"dateModified\":\"2024-05-04T04:27:58+00:00\",\"author\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/cb5556d2501da73d864cac945e8d9461\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8spring-boot-thymeleaf-tomcat-gradle%e5%bc%80%e5%8f%91%e4%b8%9a%e5%8a%a1%e5%ba%94%e7%94%a8%e6%97%b6%e7%9a%846%e4%b8%aa%e9%97%ae%e9%a2%98\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8spring-boot-thymeleaf-tomcat-gradle%e5%bc%80%e5%8f%91%e4%b8%9a%e5%8a%a1%e5%ba%94%e7%94%a8%e6%97%b6%e7%9a%846%e4%b8%aa%e9%97%ae%e9%a2%98\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8spring-boot-thymeleaf-tomcat-gradle%e5%bc%80%e5%8f%91%e4%b8%9a%e5%8a%a1%e5%ba%94%e7%94%a8%e6%97%b6%e7%9a%846%e4%b8%aa%e9%97%ae%e9%a2%98\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.silicloud.com\/zh\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u4f7f\u7528Spring Boot + Thymeleaf + Tomcat + Gradle\u5f00\u53d1\u4e1a\u52a1\u5e94\u7528\u65f6\u76846\u4e2a\u95ee\u9898\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/\",\"name\":\"Blog - Silicon Cloud\",\"description\":\"\",\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/cb5556d2501da73d864cac945e8d9461\",\"name\":\"\u6e05, \u626c\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/32a4239de8ff29adace466261d309424a1e5fe9f7e3036bf89fe03f2e3dbe717?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/32a4239de8ff29adace466261d309424a1e5fe9f7e3036bf89fe03f2e3dbe717?s=96&d=mm&r=g\",\"caption\":\"\u6e05, \u626c\"},\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/author\/qingyang\/\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8spring-boot-thymeleaf-tomcat-gradle%e5%bc%80%e5%8f%91%e4%b8%9a%e5%8a%a1%e5%ba%94%e7%94%a8%e6%97%b6%e7%9a%846%e4%b8%aa%e9%97%ae%e9%a2%98\/#local-main-organization-logo\",\"url\":\"\",\"contentUrl\":\"\",\"caption\":\"Blog - Silicon Cloud\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"\u4f7f\u7528Spring Boot + Thymeleaf + Tomcat + Gradle\u5f00\u53d1\u4e1a\u52a1\u5e94\u7528\u65f6\u76846\u4e2a\u95ee\u9898 - Blog - Silicon Cloud","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.silicloud.com\/zh\/blog\/\u4f7f\u7528spring-boot-thymeleaf-tomcat-gradle\u5f00\u53d1\u4e1a\u52a1\u5e94\u7528\u65f6\u76846\u4e2a\u95ee\u9898\/","og_locale":"zh_CN","og_type":"article","og_title":"\u4f7f\u7528Spring Boot + Thymeleaf + Tomcat + Gradle\u5f00\u53d1\u4e1a\u52a1\u5e94\u7528\u65f6\u76846\u4e2a\u95ee\u9898","og_description":"\u6709\u8bb8\u591a\u6846\u67b6\u53ef\u4ee5\u6ee1\u8db3\u60f3\u8981\u7528Java\u5236\u4f5cWEB\u5e94\u7528\u7a0b\u5e8f\u7684\u9700\u6c42\uff0c\u4f46\u5176\u4e2dSpring Boot\u5728\u5176\u4e2d\u5177\u6709\u91cd\u8981\u7684\u5b58\u5728\u611f\u3002 [&hellip;]","og_url":"https:\/\/www.silicloud.com\/zh\/blog\/\u4f7f\u7528spring-boot-thymeleaf-tomcat-gradle\u5f00\u53d1\u4e1a\u52a1\u5e94\u7528\u65f6\u76846\u4e2a\u95ee\u9898\/","og_site_name":"Blog - Silicon Cloud","article_published_time":"2023-08-01T08:05:52+00:00","article_modified_time":"2024-05-04T04:27:58+00:00","og_image":[{"url":"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d3f9037434c4406c8f378\/27-0.jpeg"}],"author":"\u6e05, \u626c","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"\u6e05, \u626c","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"5 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8spring-boot-thymeleaf-tomcat-gradle%e5%bc%80%e5%8f%91%e4%b8%9a%e5%8a%a1%e5%ba%94%e7%94%a8%e6%97%b6%e7%9a%846%e4%b8%aa%e9%97%ae%e9%a2%98\/","url":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8spring-boot-thymeleaf-tomcat-gradle%e5%bc%80%e5%8f%91%e4%b8%9a%e5%8a%a1%e5%ba%94%e7%94%a8%e6%97%b6%e7%9a%846%e4%b8%aa%e9%97%ae%e9%a2%98\/","name":"\u4f7f\u7528Spring Boot + Thymeleaf + Tomcat + Gradle\u5f00\u53d1\u4e1a\u52a1\u5e94\u7528\u65f6\u76846\u4e2a\u95ee\u9898 - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website"},"datePublished":"2023-08-01T08:05:52+00:00","dateModified":"2024-05-04T04:27:58+00:00","author":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/cb5556d2501da73d864cac945e8d9461"},"breadcrumb":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8spring-boot-thymeleaf-tomcat-gradle%e5%bc%80%e5%8f%91%e4%b8%9a%e5%8a%a1%e5%ba%94%e7%94%a8%e6%97%b6%e7%9a%846%e4%b8%aa%e9%97%ae%e9%a2%98\/#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8spring-boot-thymeleaf-tomcat-gradle%e5%bc%80%e5%8f%91%e4%b8%9a%e5%8a%a1%e5%ba%94%e7%94%a8%e6%97%b6%e7%9a%846%e4%b8%aa%e9%97%ae%e9%a2%98\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8spring-boot-thymeleaf-tomcat-gradle%e5%bc%80%e5%8f%91%e4%b8%9a%e5%8a%a1%e5%ba%94%e7%94%a8%e6%97%b6%e7%9a%846%e4%b8%aa%e9%97%ae%e9%a2%98\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.silicloud.com\/zh\/blog\/"},{"@type":"ListItem","position":2,"name":"\u4f7f\u7528Spring Boot + Thymeleaf + Tomcat + Gradle\u5f00\u53d1\u4e1a\u52a1\u5e94\u7528\u65f6\u76846\u4e2a\u95ee\u9898"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website","url":"https:\/\/www.silicloud.com\/zh\/blog\/","name":"Blog - Silicon Cloud","description":"","inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/cb5556d2501da73d864cac945e8d9461","name":"\u6e05, \u626c","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/32a4239de8ff29adace466261d309424a1e5fe9f7e3036bf89fe03f2e3dbe717?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/32a4239de8ff29adace466261d309424a1e5fe9f7e3036bf89fe03f2e3dbe717?s=96&d=mm&r=g","caption":"\u6e05, \u626c"},"url":"https:\/\/www.silicloud.com\/zh\/blog\/author\/qingyang\/"},{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8spring-boot-thymeleaf-tomcat-gradle%e5%bc%80%e5%8f%91%e4%b8%9a%e5%8a%a1%e5%ba%94%e7%94%a8%e6%97%b6%e7%9a%846%e4%b8%aa%e9%97%ae%e9%a2%98\/#local-main-organization-logo","url":"","contentUrl":"","caption":"Blog - Silicon Cloud"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/40263","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/comments?post=40263"}],"version-history":[{"count":2,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/40263\/revisions"}],"predecessor-version":[{"id":98317,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/40263\/revisions\/98317"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/media?parent=40263"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/categories?post=40263"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/tags?post=40263"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}