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

首钢建设集团山东公司网站如何做付款网站

首钢建设集团山东公司网站,如何做付款网站,全国卫生机构建设管理系统网站,中国十大培训机构影视后期现在很多开源的组件都会提供对应的 springboot-starter 包给我们去用#xff0c;要做一个 starter 包并不难。参照Spring内置的实现就好了#xff1a; 1、在工程里引入 starter 打包相关的依赖。 2、在我们工程内建 spring.factories 文件#xff0c;编写我们配置类的全限类… 现在很多开源的组件都会提供对应的 springboot-starter 包给我们去用要做一个 starter 包并不难。参照Spring内置的实现就好了 1、在工程里引入 starter 打包相关的依赖。 2、在我们工程内建 spring.factories 文件编写我们配置类的全限类名。 一、自定义步骤详解 使用AOP实现拦截方法执行和打印日志的功能 1.1、创建Starter项目 名称 zhinian-log-spring-boot-starter , 版本号是 1.0-SNAPSHOT 。且同时引入下方依赖。 1.2、引入pom依赖 ?xml version1.0 encodingUTF-8? project xmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersiongroupIdcom.zn.opit.base/groupIdartifactIdzhinian-log-spring-boot-starter/artifactIdversion1.0-SNAPSHOT/versionpropertiesmaven.compiler.source8/maven.compiler.sourcemaven.compiler.target8/maven.compiler.target/propertiesdependenciesdependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-configuration-processor/artifactIdversion2.7.13/versionoptionaltrue/optional/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-aop/artifactIdversion2.7.13/version/dependency/dependenciesbuildpluginsplugingroupIdorg.springframework.boot/groupIdartifactIdspring-boot-maven-plugin/artifactIdconfigurationclassifierexec/classifier/configuration/plugin/plugins/build/project1.3、定义Starter需要的配置类(Properties) package com.zn.opit.base.config;import org.springframework.boot.context.properties.ConfigurationProperties;ConfigurationProperties(prefix zn.log) public class ZhiNianLogProperties {private boolean enabled;public boolean isEnabled() {return enabled;}public void setEnabled(boolean enabled) {this.enabled enabled;} }如果我们需要从 application.yaml 或 application.properties 中拿到一些使用者配置的数据那么我们就需要定义一个properties类。这个properties类主要作用是将 application.yaml 或 application.properties 中的配置信息映射成实体类比如我们这里指定 prefix “zn.log” 这样我们就能将以zn.log为前缀的配置项拿到了。 1.4、编写Starter项目的业务功能 AOP切面逻辑 package com.zn.opit.base.component;import org.aspectj.lang.JoinPoint; import org.aspectj.lang.annotation.AfterReturning; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.aspectj.lang.annotation.Pointcut; import org.springframework.stereotype.Component;Aspect Component public class WebLogAspect {Pointcut(execution(* *..*Controller.*(..)))public void webLog(){}Before(webLog())public void doBefore(JoinPoint joinPoint) throws Throwable {//方法开始前打印开始日志System.out.println(zn-starter --------doBefore);}AfterReturning(returning ret, pointcut webLog())public void doAfterReturning(Object ret) throws Throwable {// 处理完请求打印结束日志System.out.println(zn-starter --------doAfterReturning);} }1.5、编写自动配置类 package com.zn.opit.base.config;import com.zn.opit.base.component.WebLogAspect; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration;Configuration // 表示该类是一个配置类 EnableConfigurationProperties({ZhiNianLogProperties.class}) // 该注解的作用是为 xxxProperties 开启属性配置功能并将这个类以组件的形式注入到容器中 ConditionalOnProperty(prefix zn.log, value enabled) // 当指定的配置项等于你想要的时候配置类生效 public class ZnLogAutoConfig {Bean // Bean该注解用于将方法的返回值以 Bean 对象的形式添加到容器中ConditionalOnMissingBean // ConditionalOnMissingBean(xxx.class)该注解表示当容器中没有 xxx 类时该方法才生效public WebLogAspect webLogAspect() {return new WebLogAspect();} }1.6、编写spring.factories文件加载自动配置类 org.springframework.boot.autoconfigure.EnableAutoConfigurationcom.zn.opit.base.config.ZnLogAutoConfig1.7、构建starter制品包 buildpluginsplugingroupIdorg.springframework.boot/groupIdartifactIdspring-boot-maven-plugin/artifactIdconfigurationclassifierexec/classifier/configuration/plugin/plugins /build在项目根目录下执行mvn clean install打包并放到maven仓库中(maven仓库地址和配置有关) 显示build success表示starter制品包打包完成 二、其它项目引用验证 2.1、pom中引入自定义starter依赖 ?xml version1.0 encodingUTF-8? project xmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersiongroupIdcom.zn.opit.base/groupIdartifactIdzhinian-log-starter-test/artifactIdversion1.0-SNAPSHOT/versionpropertiesmaven.compiler.source8/maven.compiler.sourcemaven.compiler.target8/maven.compiler.target/propertiesdependenciesdependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactIdversion2.7.13/version/dependencydependencygroupIdcom.zn.opit.base/groupIdartifactIdzhinian-log-spring-boot-starter/artifactIdversion1.0-SNAPSHOT/version/dependency/dependencies /project2.2、写一个Controller接口 (要符合starter里的aop拦截表达式规则否则拦截不到) package com.zn.opit.base.controller;import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController;RequestMapping(/hello) RestController public class HelloController {GetMapping(/test)public String test() {return SUCCESS;} }2.3、配置文件 application.properties zn.log.enabledtrue server.port80772.4、验证 启动业务项目访问接口验证 至此一个简单的starter示例就写完了。
http://www.zqtcl.cn/news/103354/

相关文章:

  • 门户网站的盈利模式网站建设中备案
  • 代码需求网站织梦怎么关闭网站
  • 浙江工信部网站备案查询东圃做网站
  • icp网站域名怎么填写官方网站建设银行年利息是多少钱
  • 沈阳做网站好的信息流优化师证书
  • 做招聘网站创业seo优化工作
  • 如何维护网站建设外卖网站建设价钱
  • 南宁保洁网站建设乌克兰服装网站建设
  • ppt链接网站怎么做的nas云存储做视频网站
  • 上海网站制作公司联系方式设计素材网站照片
  • 林州网站建设价格网络舆情是什么意思
  • 网站外链平台的建设方法平台类型(至少5个)?兰州道路建设情况网站
  • 网站建立健全举报工作机制设计电子商务网站主页
  • 广州市建设工程交易服务中心网站沈阳百度推广哪家好
  • 个人网站备案需要什么网站建立的重要性
  • wordpress用户名西安seo代理计费
  • 网站建设前准备工作手机上传视频网站开发
  • 海口网站建设是什么意思wordpress推广码
  • 杭州市住房和城乡建设厅网站海南网站建设设计
  • 网站建设平台一般多少钱wordpress 本地上传服务器
  • 怎么给网站命名男女做羞羞羞的网站
  • 北京响应式网站建设公司信息流推广方式
  • 一级a做爰片迅雷网站微分销系统定制开发
  • 山东网站建设工作室网页设计全部代码
  • 用c 做网站可以吗注册网站什么要求
  • 销售网站排名销售型网站模板
  • wordpress 汽车宁波seo整体优化
  • 网站建设公司在哪里宣传c2c旅游电子商务平台
  • 网站查看空间商网站不提交表单
  • 空间怎么上传网站企业所得税怎么算公式