From 9159e2ed2293722db0c9a42024c00d38c1a2cd62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90li?= <15040126243@163.com> Date: Thu, 13 May 2021 09:16:28 +0800 Subject: [PATCH] =?UTF-8?q?fix=20vue=E4=B8=8Eboot=E6=95=B4=E5=90=88?= =?UTF-8?q?=E6=89=93=E5=8C=85=E4=B8=8Eadmin=E9=A1=B5=E9=9D=A2=E8=B7=AF?= =?UTF-8?q?=E7=94=B1=E5=86=B2=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/application.yml | 4 +++ .../framework/config/AdminServerConfig.java | 34 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml index 85007285..6ab30306 100644 --- a/ruoyi-admin/src/main/resources/application.yml +++ b/ruoyi-admin/src/main/resources/application.yml @@ -79,6 +79,10 @@ spring: restart: # 热部署开关 enabled: true + # 与vue整合部署使用 + thymeleaf: + # 将系统模板放置到最前面 否则会与 springboot-admin 页面冲突 + template-resolver-order: 1 application: name: ruoyi-vue-plus boot: diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/AdminServerConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/AdminServerConfig.java index 5fa65c1e..59fed507 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/AdminServerConfig.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/AdminServerConfig.java @@ -1,15 +1,25 @@ package com.ruoyi.framework.config; import de.codecentric.boot.admin.server.config.EnableAdminServer; +import org.springframework.beans.factory.ObjectProvider; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration; +import org.springframework.boot.autoconfigure.thymeleaf.ThymeleafProperties; import org.springframework.boot.task.TaskExecutorBuilder; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Lazy; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; +import org.thymeleaf.dialect.IDialect; +import org.thymeleaf.spring5.ISpringTemplateEngine; +import org.thymeleaf.spring5.SpringTemplateEngine; +import org.thymeleaf.templateresolver.ITemplateResolver; +import java.util.Comparator; +import java.util.LinkedHashSet; +import java.util.Set; import java.util.concurrent.Executor; +import java.util.stream.Collectors; /** * springboot-admin server配置类 @@ -26,4 +36,28 @@ public class AdminServerConfig { public ThreadPoolTaskExecutor applicationTaskExecutor(TaskExecutorBuilder builder) { return builder.build(); } + + /** + * 解决 admin 与 项目 页面的交叉引用 将 admin 的路由放到最后 + * @param properties + * @param templateResolvers + * @param dialects + * @return + */ + @Bean + @ConditionalOnMissingBean(ISpringTemplateEngine.class) + SpringTemplateEngine templateEngine(ThymeleafProperties properties, + ObjectProvider templateResolvers, ObjectProvider dialects) { + SpringTemplateEngine engine = new SpringTemplateEngine(); + engine.setEnableSpringELCompiler(properties.isEnableSpringElCompiler()); + engine.setRenderHiddenMarkersBeforeCheckboxes(properties.isRenderHiddenMarkersBeforeCheckboxes()); + templateResolvers.orderedStream().forEach(engine::addTemplateResolver); + dialects.orderedStream().forEach(engine::addDialect); + Set templateResolvers1 = engine.getTemplateResolvers(); + templateResolvers1 = templateResolvers1.stream() + .sorted(Comparator.comparing(ITemplateResolver::getOrder)) + .collect(Collectors.toCollection(LinkedHashSet::new)); + engine.setTemplateResolvers(templateResolvers1); + return engine; + } }