当前位置: 首页 > news >正文

网站icp备案信息是什么网上怎么自己做网站

网站icp备案信息是什么,网上怎么自己做网站,天津建设网工程信息网,哈尔滨住房和城乡建设局git hok json在某些情况下#xff0c;我们必须知道部署到远程服务器的Web应用程序的确切版本。 例如#xff0c;客户可能想知道我们是否已经在服务器X上部署了错误修复程序。 当然#xff0c;我们可以尝试使用“传统”方法找到该问题的答案。 问题是#xff1a; 没有人不… git hok json 在某些情况下我们必须知道部署到远程服务器的Web应用程序的确切版本。 例如客户可能想知道我们是否已经在服务器X上部署了错误修复程序。 当然我们可以尝试使用“传统”方法找到该问题的答案。 问题是 没有人不记得是谁更新了服务器X或何时更新了服务器X。 更新它的人不记得哪个是构建中包含的最后一次提交。 换句话说我们被搞砸了。 我们可以尝试测试服务器X上是否仍然存在该错误但这对我们没有帮助因为我们的错误修复可能无法正常工作。 这篇博客文章描述了我们如何解决这个问题。 让我们从提取Git存储库的构建时状态开始。 如果使用Spring Boot则应使用Spring Boot Actuator 。 它可以帮助您发布有关Git存储库状态的信息 。 如果您尚未阅读以下博客文章 则应先阅读它们然后再继续阅读此博客文章 从槽中弹起将属性值注入配置Bean描述了为什么应将属性值注入配置Bean并帮助您做到这一点。 从槽中弹跳以JSON返回运行时配置描述了如何将Web应用程序的运行时配置写入日志文件并将其作为JSON返回。 提取我们的Git仓库的构建时间状态 我们可以使用Maven Git Commit Id插件提取Git存储库的构建时状态。 让我们了解如何配置Maven Git Commit Id插件并将提取的信息添加到属性文件中。 首先 我们需要配置资源目录的位置并确保将从属性文件中找到的属性占位符替换为实际的属性值。 我们可以通过将以下XML添加到pom.xml文件的build部分中来实现 resourcesresourcedirectorysrc/main/resources/directoryfilteringtrue/filteringincludesinclude**/*.properties/include/includes/resource /resources 其次 我们需要配置Maven Git Commit Id插件。 我们可以按照以下步骤进行操作 将Maven Git提交ID插件添加到我们的构建中。 确保在默认生命周期的初始化阶段调用了Maven Git Commit Id插件的修订目标。 配置.git目录的位置。 我们需要将以下XML添加到pom.xml文件的plugins部分 plugingroupIdpl.project13.maven/groupIdartifactIdgit-commit-id-plugin/artifactIdversion2.1.13/version!--Ensure that the revision goal is invoked during the initializephase.--executionsexecutiongoalsgoalrevision/goal/goals/execution/executionsconfiguration!--Configure the location of the .git directory.--dotGitDirectory${project.basedir}/../.git/dotGitDirectory/configuration /plugin 如果您对Maven Git Commit Id插件的默认配置不满意则应仔细阅读其自述文件 使用该插件提供了带注释的XML配置文件该文件描述了Maven Git Commit Id插件的配置。 深入的配置选项描述了Maven Git Commit Id插件的每个配置选项。 第三 我们需要创建属性文件其中包含从Git存储库中提取的信息。 application.properties文件如下所示 git.tags${git.tags} git.branch${git.branch} git.dirty${git.dirty} git.remote.origin.url${git.remote.origin.url}git.commit.id${git.commit.id} git.commit.id.abbrev${git.commit.id.abbrev} git.commit.id.describe${git.commit.id.describe} git.commit.id.describe-short${git.commit.id.describe-short} git.commit.user.name${git.commit.user.name} git.commit.user.email${git.commit.user.email} git.commit.message.full${git.commit.message.full} git.commit.message.short${git.commit.message.short} git.commit.time${git.commit.time}git.build.user.name${git.build.user.name} git.build.user.email${git.build.user.email} git.build.time${git.build.time} 现在我们已经配置了Maven Git Commit Id插件。 编译项目时将从application.properties文件中找到的属性占位符替换为从Git存储库中提取的实际属性值。 从target / classes目录中找到的application.properties文件如下所示 git.tags git.branchmaster git.dirtytrue git.remote.origin.urlgitgithub.com:pkainulainen/spring-from-the-trenches.gitgit.commit.id1bdfe9cf22b550a3ebe170f60df165e5c26448f9 git.commit.id.abbrev1bdfe9c git.commit.id.describe1bdfe9c-dirty git.commit.id.describe-short1bdfe9c-dirty git.commit.user.namePetri Kainulainen git.commit.user.emailpetri.kainulainengmail.com git.commit.message.fullDeclare PropertySourcesPlaceholderConfigurer in a static Bean method git.commit.message.shortDeclare PropertySourcesPlaceholderConfigurer in a static Bean method git.commit.time16.04.2015 23:35:23 EESTgit.build.user.namePetri Kainulainen git.build.user.emailpetri.kainulainengmail.com git.build.time18.04.2015 17:07:55 EEST 如果您不想创建属性文件则Maven Git Commit Id插件可以为您生成一个 。 让我们继续前进找出如何将Git提交信息注入到属性bean中。 将Git提交信息注入到属性Bean中 我们需要创建以下描述的三个属性bean类 BuildProperties类包含有关开始构建的人的信息。 CommitProperties类包含有关构建中包含的最新提交的信息。 GitProperties类包含一些“公共”属性例如branch tags和remoteOriginUrl 。 它还包含对BuildProperties和CommitProperties对象的引用。 属性Bean与以下内容中描述的配置Bean相似 我以前的博客文章 。 我为这些类使用不同的后缀的原因是它们不是Web应用程序配置的一部分。 它们仅包含写入日志文件并以JSON返回的信息。 另外如果您不知道为什么要将属性值注入特殊的bean类中以及如何将其值注入则应阅读我的博客文章该文章回答了这两个问题 。 首先 我们需要创建BuildProperties类。 此类具有final time userEmail和userName字段。 通过使用构造函数注入将实际字段值注入到这些字段中。 BuildProperties类的源代码如下所示 import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component;Component public class BuildProperties {private final String time;private final String userEmail;private final String userName;Autowiredpublic BuildProperties(Value(${git.build.time}) String time,Value(${git.build.user.email}) String userEmail,Value(${git.build.user.name}) String userName) {this.time time;this.userEmail userEmail;this.userName userName;}//Getters are omitted for the sake of clarity } 其次 我们需要创建CommitProperties类。 此类具有最后的describe describeShort fullMessage id idAbbrev shortMessage time userEmail和userName字段。 通过使用构造函数注入将实际属性值注入到这些字段中。 CommitProperties类的源代码如下所示 import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component;Component public class CommitProperties {private final String describe;private final String describeShort;private final String fullMessage;private final String id;private final String idAbbrev;private final String shortMessage;private final String time;private final String userEmail;private final String userName;Autowiredpublic CommitProperties(Value(${git.commit.id.describe}) String describe,Value(${git.commit.id.describe-short}) String describeShort,Value(${git.commit.message.full}) String fullMessage,Value(${git.commit.id}) String id,Value(${git.commit.id.abbrev}) String idAbbrev,Value(${git.commit.message.short}) String shortMessage,Value(${git.commit.time}) String time,Value(${git.commit.user.email}) String userEmail,Value(${git.commit.user.name}) String userName) {this.describe describe;this.describeShort describeShort;this.fullMessage fullMessage;this.id id;this.idAbbrev idAbbrev;this.shortMessage shortMessage;this.time time;this.userEmail userEmail;this.userName userName;}//Getters are omitted for the sake of clarity } 第三 我们需要创建GitProperties类。 此类具有最后的branch build commit dirty remoteOriginUrl和tags字段。 通过使用构造函数注入将实际字段值或对象注入这些字段。 GitProperties类的源代码如下所示 import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component;Component public class GitProperties {private String branch;private final BuildProperties build;private final CommitProperties commit;private final boolean dirty;private final String remoteOriginUrl;private final String tags;Autowiredpublic GitProperties(Value(${git.branch}) String branch,BuildProperties build,CommitProperties commit,Value(${git.dirty}) boolean dirty,Value(${git.remote.origin.url}) String remoteOriginUrl,Value(${git.tags}) String tags) {this.branch branch;this.build build;this.commit commit;this.dirty dirty;this.remoteOriginUrl remoteOriginUrl;this.tags tags;}//Getters are omitted for the sake of clarity } 让我们继续并将Git提交信息写入日志文件。 将Git提交信息写入日志文件 下一步是将Git提交信息信息写入日志文件。 让我们找出如何做到这一点。 首先 我们必须向BuildProperties CommitProperties和GitProperties类添加toString方法并使用ToStringBuilder类实现这些方法。 BuildProperties类的源代码如下所示 import org.apache.commons.lang3.builder.ToStringBuilder; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component;Component public class BuildProperties {private final String time;private final String userEmail;private final String userName;Autowiredpublic BuildProperties(Value(${git.build.time}) String time,Value(${git.build.user.email}) String userEmail,Value(${git.build.user.name}) String userName) {this.time time;this.userEmail userEmail;this.userName userName;}//Getters are omitted for the sake of clarityOverridepublic String toString() {return new ToStringBuilder(this).append(time, this.time).append(userEmail, this.userEmail).append(userName, this.userName).toString();} } CommitProperties类的源代码如下所示 import org.apache.commons.lang3.builder.ToStringBuilder; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component;Component public class CommitProperties {private final String describe;private final String describeShort;private final String fullMessage;private final String id;private final String idAbbrev;private final String shortMessage;private final String time;private final String userEmail;private final String userName;Autowiredpublic CommitProperties(Value(${git.commit.id.describe}) String describe,Value(${git.commit.id.describe-short}) String describeShort,Value(${git.commit.message.full}) String fullMessage,Value(${git.commit.id}) String id,Value(${git.commit.id.abbrev}) String idAbbrev,Value(${git.commit.message.short}) String shortMessage,Value(${git.commit.time}) String time,Value(${git.commit.user.email}) String userEmail,Value(${git.commit.user.name}) String userName) {this.describe describe;this.describeShort describeShort;this.fullMessage fullMessage;this.id id;this.idAbbrev idAbbrev;this.shortMessage shortMessage;this.time time;this.userEmail userEmail;this.userName userName;}//Getters are omitted for the sake of clarityOverridepublic String toString() {return new ToStringBuilder(this).append(describe, this.describe).append(describeShort, this.describeShort).append(fullMessage, this.fullMessage).append(id, this.id).append(idAbbrev, this.idAbbrev).append(shortMessage, this.shortMessage).append(time, this.time).append(userEmail, this.userEmail).append(userName, this.userName).toString();} } GitProperties类的源代码如下所示 import org.apache.commons.lang3.builder.ToStringBuilder; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component;Component public class GitProperties {private String branch;private final BuildProperties build;private final CommitProperties commit;private final boolean dirty;private final String remoteOriginUrl;private final String tags;Autowiredpublic GitProperties(Value(${git.branch}) String branch,BuildProperties build,CommitProperties commit,Value(${git.dirty}) boolean dirty,Value(${git.remote.origin.url}) String remoteOriginUrl,Value(${git.tags}) String tags) {this.branch branch;this.build build;this.commit commit;this.dirty dirty;this.remoteOriginUrl remoteOriginUrl;this.tags tags;}//Getters are omitted for the sake of clarityOverridepublic String toString() {return new ToStringBuilder(this).append(branch, this.branch).append(build, this.build).append(commit, this.commit).append(dirty, this.dirty).append(remoteOriginUrl, this.remoteOriginUrl).append(tags, this.tags).toString();} } 其次 我们必须在启动应用程序时将Git提交信息写入日志文件。 我们可以按照以下步骤进行操作 将静态的最终Logger字段添加到GitProperties类并使用LoggerFactory类创建一个新的Logger对象。 将writeGitCommitInformationToLog方法添加到GitProperties类并使用PostConstruct批注对其进行批注。 这样可以确保Spring容器在将创建的bean对象的依赖项注入到其中之后调用此方法。 通过将Git提交信息写入日志文件来实现writeGitCommitInformationToLog方法。 完成这些更改后 GitProperties类的源代码如下所示 import org.apache.commons.lang3.builder.ToStringBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component;import javax.annotation.PostConstruct;Component public class GitProperties {private static final Logger LOGGER LoggerFactory.getLogger(GitProperties.class);private String branch;private final BuildProperties build;private final CommitProperties commit;private final boolean dirty;private final String remoteOriginUrl;private final String tags;Autowiredpublic GitProperties(Value(${git.branch}) String branch,BuildProperties build,CommitProperties commit,Value(${git.dirty}) boolean dirty,Value(${git.remote.origin.url}) String remoteOriginUrl,Value(${git.tags}) String tags) {this.branch branch;this.build build;this.commit commit;this.dirty dirty;this.remoteOriginUrl remoteOriginUrl;this.tags tags;}//Getters are omitted for the sake of clarityOverridepublic String toString() {return new ToStringBuilder(this).append(branch, this.branch).append(build, this.build).append(commit, this.commit).append(dirty, this.dirty).append(remoteOriginUrl, this.remoteOriginUrl).append(tags, this.tags).toString();}PostConstructpublic void writeGitCommitInformationToLog() {LOGGER.info(Application was built by using the Git commit: {}, this);} } 启动Web应用程序时我们应该从其日志文件中找到以下信息 INFO - GitProperties - Application was built by using the Git commit: net.petrikainulainen.spring.trenches.config.GitProperties47044f7d[branchmaster,buildnet.petrikainulainen.spring.trenches.config.BuildProperties7b14c61[time19.04.2015 00:47:37 EEST,userEmailpetri.kainulainengmail.com,userNamePetri Kainulainen],commitnet.petrikainulainen.spring.trenches.config.CommitProperties8fcc534[describe1bdfe9c-dirty,describeShort1bdfe9c-dirty,fullMessageDeclare PropertySourcesPlaceholderConfigurer in a static Bean method,id1bdfe9cf22b550a3ebe170f60df165e5c26448f9,idAbbrev1bdfe9c,shortMessageDeclare PropertySourcesPlaceholderConfigurer in a static Bean method,time16.04.2015 23:35:23 EEST,userEmailpetri.kainulainengmail.com,userNamePetri Kainulainen],dirtytrue,remoteOriginUrlgitgithub.com:pkainulainen/spring-from-the-trenches.git,tags ] 该信息写在一行中但是我对它进行了格式化因为我想使其更易于阅读。 让我们了解如何将Git提交信息作为JSON返回。 以JSON形式返回Git提交信息 之前我们创建了一个控制器类 该类将Web应用程序的运行时配置作为JSON返回。 让我们修改此类以将Git提交信息作为JSON返回。 我们可以按照以下步骤进行操作 将最后的GitProperties字段添加到PropertiesController类。 使用构造函数注入将GitProperties bean注入到创建的控制器bean中。 创建一个控制器方法来处理发送到url/ version的GET请求并通过返回GitProperties对象来实现它。 PropertiesController的源代码如下所示 import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController;RestController final class PropertiesController {private final ApplicationProperties applicationProperties;private final GitProperties gitProperties;AutowiredPropertiesController(ApplicationProperties applicationProperties, GitProperties gitProperties) {this.applicationProperties applicationProperties;this.gitProperties gitProperties;}RequestMapping(value /config, method RequestMethod.GET)ApplicationProperties getAppConfiguration() {return applicationProperties;}RequestMapping(value /version, method RequestMethod.GET)GitProperties getVersion() {return gitProperties;} } 当我们将GET请求发送到url/ version时我们的控制器方法将返回以下JSON {branch:master,build:{time:19.04.2015 00:47:37 EEST,userEmail:petri.kainulainengmail.com,userName:Petri Kainulainen},commit:{describe:1bdfe9c-dirty,describeShort:1bdfe9c-dirty,fullMessage:Declare PropertySourcesPlaceholderConfigurer in a static Bean method,id:1bdfe9cf22b550a3ebe170f60df165e5c26448f9,idAbbrev:1bdfe9c,shortMessage:Declare PropertySourcesPlaceholderConfigurer in a static Bean method,time:16.04.2015 23:35:23 EEST,userEmail:petri.kainulainengmail.com,userName:Petri Kainulainen},dirty:true,remoteOriginUrl:gitgithub.com:pkainulainen/spring-from-the-trenches.git,tags: } 我们不应该允许所有人访问我们应用程序的Git提交信息。 如果这将是一个真实的应用程序我们应确保只有管理员才能访问此信息。 让我们继续并总结从这篇博客文章中学到的知识。 摘要 这篇博客文章教会了我们三件事 我们可以使用Maven Git Commit Id插件从Git存储库中提取构建时状态。 我们可以通过重写属性bean类的toString方法并将这些bean的属性值注入到日志文件中后将Git提交信息写入日志文件。 通过创建返回“根”属性bean对象 GitProperties 的控制器方法我们可以将Git提交信息作为JSON返回。 PS您可以从Github获得此博客文章的示例应用程序 。 翻译自: https://www.javacodegeeks.com/2015/04/spring-from-the-trenches-returning-git-commit-information-as-json.htmlgit hok json
http://www.zqtcl.cn/news/921368/

相关文章:

  • 招标网站哪个好适合学生做网站的图片
  • 台州seo网站排名优化外包服务公司
  • 汉川网站推广服务网页站点不安全
  • wdcp网站搬家嘉兴做网站优化的公司
  • 网站规划和建设度假区网站建设方案
  • 做网站前端用什么软件好在线种子资源网
  • 怎样修改网站关键词昌平做网站的公司
  • 网站建设调研文档网站最下面版权模板
  • 建外贸网站有效果吗开发电商平台需要多少钱
  • 成都网站建设维护网页制作价格私活
  • 建设银行网站登陆不上做本地的分类信息网站
  • 公司网站建设哪里实惠网页设计作业百度网盘
  • 如何seo网站挣钱不同企业的网络营销网站
  • 自己做网站有什么用网站怎样设计网址
  • 做任务的网站有那些wordpress链接在哪里
  • 免费建站模板网站招聘网站哪个好
  • 网站建站推广是啥意思高端网站建设浩森宇特
  • 长治电子商务网站建设中国建设银行总行官方网站
  • 整站营销系统厚街镇网站仿做
  • 舆情分析网站wordpress文章聚合
  • 中国建设银行网站在哪上市cpa自己做网站
  • 网站建设服务支持jquery插件 wordpress
  • 最有效的100个营销方法seo工作室
  • wordpress o2o主题嘉兴网站优化联系方式
  • 网站建设最基础的是什么网站怎么做架构
  • 网站底部怎么修改网站服务器是干什么的
  • 网络营销是营销的网络化吗广州推广seo
  • 茌平做网站推广网站刷链接怎么做的
  • 东莞网站优化推广Wordpress的根目录在哪
  • 备案的网站建设书是什么意思跨境电商代运营公司十强