diff --git a/blog-core/src/main/java/com/zyd/blog/framework/config/FreeMarkerConfig.java b/blog-core/src/main/java/com/zyd/blog/framework/config/FreeMarkerConfig.java index 2b6280aaa81460fbf676bfb3f3aad1fb19b032af..80edeeec93164a6236e015520af6efbde33c842d 100644 --- a/blog-core/src/main/java/com/zyd/blog/framework/config/FreeMarkerConfig.java +++ b/blog-core/src/main/java/com/zyd/blog/framework/config/FreeMarkerConfig.java @@ -2,6 +2,7 @@ package com.zyd.blog.framework.config; import com.jagregory.shiro.freemarker.ShiroTags; import com.zyd.blog.business.service.SysConfigService; +import com.zyd.blog.framework.property.AppProperties; import com.zyd.blog.framework.tag.ArticleTags; import com.zyd.blog.framework.tag.CustomTags; import freemarker.template.TemplateModelException; @@ -29,6 +30,8 @@ public class FreeMarkerConfig { protected ArticleTags articleTags; @Autowired private SysConfigService configService; + @Autowired + private AppProperties appProperties; /** * 添加自定义标签 @@ -39,6 +42,7 @@ public class FreeMarkerConfig { configuration.setSharedVariable("articleTag", articleTags); try { configuration.setSharedVariable("config", configService.getConfigs()); + configuration.setSharedVariable("appInfo", appProperties); //shiro标签 configuration.setSharedVariable("shiro", new ShiroTags()); } catch (TemplateModelException e) { diff --git a/blog-core/src/main/java/com/zyd/blog/framework/property/AppProperties.java b/blog-core/src/main/java/com/zyd/blog/framework/property/AppProperties.java index 34e47e427cffe9e95dfa912b0fb57b30f3c82330..3ab36b47b3a905ca915bcdd51301d1144a9fdd41 100644 --- a/blog-core/src/main/java/com/zyd/blog/framework/property/AppProperties.java +++ b/blog-core/src/main/java/com/zyd/blog/framework/property/AppProperties.java @@ -19,6 +19,23 @@ public class AppProperties { /** * 是否启用验证码 */ - public boolean enableKaptcha = false; + private boolean enableKaptcha = false; + + /** + * 是否在项目启动时,打印配置文件中的 【数据库配置】,包括 mysql、redis,默认关闭,生产环境不建议开启 + */ + private boolean enabledPrintConfig; + + /** + * 是否启用 redis 切面缓存。 + *

+ * 优先级高于 {@link com.zyd.blog.business.annotation.RedisCache#enable()} 配置 + */ + private boolean enableRedisCache; + + /** + * 系统版本,不建议修改。有 OneBlog 作者定时更新 + */ + private String version; } diff --git a/blog-core/src/main/java/com/zyd/blog/framework/runner/BlogApplicationRunner.java b/blog-core/src/main/java/com/zyd/blog/framework/runner/BlogApplicationRunner.java index b943ea5bb7279a99c46c525817079fa7b8e3a923..4c7695c2d1a585d51682af2ae8b39f106f548f25 100644 --- a/blog-core/src/main/java/com/zyd/blog/framework/runner/BlogApplicationRunner.java +++ b/blog-core/src/main/java/com/zyd/blog/framework/runner/BlogApplicationRunner.java @@ -1,5 +1,6 @@ package com.zyd.blog.framework.runner; +import com.zyd.blog.framework.property.AppProperties; import com.zyd.blog.framework.property.RedisProperties; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -30,10 +31,8 @@ public class BlogApplicationRunner extends ContextLoaderListener implements Appl @Value("${server.port}") private int port; - @Value("${spring.profiles.active}") - private String profile; - @Value("${app.enabledConfigLog}") - private Boolean enabledConfigLog; + @Autowired + private AppProperties appProperties; @Autowired private DataSourceProperties dataSourceProperties; @@ -50,8 +49,9 @@ public class BlogApplicationRunner extends ContextLoaderListener implements Appl @Override public void contextInitialized(ServletContextEvent event) { - if (null != enabledConfigLog && enabledConfigLog) { - log.info("博客关键配置信息:"); + log.info("博客关键配置信息:"); + log.info("current version:{}", appProperties.getVersion()); + if (appProperties.isEnabledConfigLog()) { String[] activeProfiles = configurableApplicationContext.getEnvironment().getActiveProfiles(); if (ObjectUtils.isEmpty(activeProfiles)) { String[] defaultProfiles = configurableApplicationContext.getEnvironment().getDefaultProfiles(); diff --git a/blog-core/src/main/resources/config/application-center.yml b/blog-core/src/main/resources/config/application-center.yml index 89400da2fb2efc8e7bea53e909e24626902d1374..b639c6ec5d33efddf4e78d23226912e50777d9c9 100644 --- a/blog-core/src/main/resources/config/application-center.yml +++ b/blog-core/src/main/resources/config/application-center.yml @@ -1,4 +1,41 @@ spring: + ####### database Config ####### + datasource: + druid: + connection-init-sqls: set names utf8mb4 + driver-class-name: com.mysql.jdbc.Driver + type: com.alibaba.druid.pool.DruidDataSource + url: jdbc:mysql://${ONEBLOG_DATASOURCE_HOST:127.0.0.1}:${ONEBLOG_DATASOURCE_PORT:3306}/${ONEBLOG_DATASOURCE_DATABASE_NAME:dblog}?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&useSSL=false&allowPublicKeyRetrieval=true + username: ${ONEBLOG_DATASOURCE_USERNAME:root} + password: ${ONEBLOG_DATASOURCE_PASSWORD:root} + + ####### Redis Config ####### + redis: + database: ${ONEBLOG_REDIS_DATABASE_INDEX:1} + # Redis服务器地址 + host: ${ONEBLOG_REDIS_HOST:127.0.0.1} + # Redis服务器连接端口 + port: ${ONEBLOG_REDIS_PORT:6379} + # Redis服务器连接密码(默认为空) + password: ${ONEBLOG_REDIS_PASSWORD:123456ZHYD} + jedis: + pool: + # 连接池最大连接数(使用负值表示没有限制) + max-active: 8 + # 连接池最大阻塞等待时间(使用负值表示没有限制) + max-wait: -1ms + # 连接池中的最大空闲连接 + max-idle: 8 + # 连接池中的最小空闲连接 + min-idle: 0 + # 连接超时时间(毫秒) + timeout: 5000ms + # 默认的数据过期时间,主要用于shiro权限管理 + expire: 2592000 + + ####### redis缓存服务配置 ####### + session: + store-type: redis # 指定默认MimeMessage的编码,默认为: UTF-8 mail: default-encoding: UTF-8 @@ -24,19 +61,7 @@ spring: mail.smtp.connectiontimeout: 50000 mail.smtp.timeout: 30000 mail.smtp.writetimeout: 50000 - # Redis数据库索引(默认为0) - redis: - jedis: - pool: - # 连接池最大连接数(使用负值表示没有限制) - max-active: 8 - # 连接池最大阻塞等待时间(使用负值表示没有限制) - max-wait: -1ms - # 连接池中的最大空闲连接 - max-idle: 8 - # 连接池中的最小空闲连接 - min-idle: 0 - # 连接超时时间(毫秒) - timeout: 5000ms - # 默认的数据过期时间,主要用于shiro权限管理 - expire: 2592000 + +app: + version: v2.2.7 + enableRedisCache: false diff --git a/blog-web/src/main/resources/templates/layout/footer.ftl b/blog-web/src/main/resources/templates/layout/footer.ftl index 0d1b3a81d9adea285580f48c74f9f8a12b958088..17a1f283913993838b3e3b23f77c64b8f8581af6 100644 --- a/blog-web/src/main/resources/templates/layout/footer.ftl +++ b/blog-web/src/main/resources/templates/layout/footer.ftl @@ -131,7 +131,7 @@

-

<#if config.copyright!>${config.copyright} | Powered by OneBlog

+

<#if config.copyright!>${config.copyright} | Powered by OneBlog ${appInfo.version!}

<#if url?? && (url == "index")>