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

阜阳商城网站建设在手机上建网站

阜阳商城网站建设,在手机上建网站,北京网站建设百度排名,平顶山有做网站的公司声明#xff1a;原文作者#xff1a;yuan_404 文章目录1. 说明2 . 编写启动器3 . 新建项目测试自己写的启动器1. 说明 启动器模块是一个 空 jar 文件#xff0c;仅提供辅助性依赖管理#xff0c;这些依赖可能用于自动装配或者其他类库 命名归约#xff1a; 官方命名原文作者yuan_404 文章目录1. 说明2 . 编写启动器3 . 新建项目测试自己写的启动器1. 说明 启动器模块是一个 空 jar 文件仅提供辅助性依赖管理这些依赖可能用于自动装配或者其他类库 命名归约 官方命名 前缀spring-boot-starter-xxx比如spring-boot-starter-web… 自定义命名 xxx-spring-boot-starter比如mybatis-spring-boot-starter 2 . 编写启动器 在IDEA中新建一个空项目 spring-boot-starter-diy 新建一个普通Maven模块demo-spring-boot-starter 新建一个Springboot模块demo-spring-boot-starter-autoconfigure 点击apply即可基本结构 在starter 中 导入 autoconfigure 的依赖 !-- 启动器 -- dependencies!-- 引入自动配置模块 --dependencygroupIdcom.demo/groupIdartifactIddemo-spring-boot-starter-autoconfigure/artifactIdversion0.0.1-SNAPSHOT/version/dependency /dependencies 将 autoconfigure 项目下Pom中加入依赖 dependenciesdependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-configuration-processor/artifactIdoptionaltrue/optional/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-autoconfigure/artifactId/dependency /dependencies 说明 第一个依赖 主要是为编译器配置的 可以根据properties 鼠标右键 点到用这个属性的类上个 第二个依赖 主要是为了自动装配 编写HelloProperties 配置类 // 前缀 demo.hello ConfigurationProperties(prefix demo.hello) public class HelloProperties {private String prefix;private String suffix;public String getPrefix() {return prefix;}public void setPrefix(String prefix) {this.prefix prefix;}public String getSuffix() {return suffix;}public void setSuffix(String suffix) {this.suffix suffix;} } 这里我们要读取的配置就是demo.hello.prefix 和 demo.hello.suffix 的值 ConfigurationProperties注解的作用就是读取配置文件指定属性的值 编写一个自己的服务 public class HelloService {HelloProperties helloProperties;public HelloProperties getHelloProperties() {return helloProperties;}public void setHelloProperties(HelloProperties helloProperties) {this.helloProperties helloProperties;}public String sayHello(String name){return helloProperties.getPrefix() name helloProperties.getSuffix();} } 编写自动配置类并注入bean测试 Configuration ConditionalOnWebApplication //web应用生效 EnableConfigurationProperties(HelloProperties.class) public class HelloServiceAutoConfiguration {AutowiredHelloProperties helloProperties;Beanpublic HelloService helloService(){HelloService service new HelloService();service.setHelloProperties(helloProperties);return service;} } 说明 Configuration 标识本类是配置类相当于spring中application.xml EnableConfigurationProperties(HelloProperties.class) 如果 HelloProperties 中有注解ConfigurationProperties 那么这个类就 会被加到spring上下文的容器中也就是可以通过Autowire来注入 ConditionalOnClass 当类路径下有指定类的情况下 才进行下一步 ConditionalOnMissingBean 当spring容器中没有这个Bean的时候才进行下一步 在resources编写一个自己的 META-INF\spring.factories java # Auto Configure org.springframework.boot.autoconfigure.EnableAutoConfiguration\ com.demo.config.HelloServiceAutoConfiguration编写完成后可以安装到maven仓库中 项目包结构 3 . 新建项目测试自己写的启动器 新建一个SpringBoot 项目(需要引入 web 的启动器) 导入我们自己写的启动器 dependencygroupIdcom.demo/groupIdartifactIddemo-spring-boot-starter/artifactIdversion1.0-SNAPSHOT/version /dependency 编写一个 HelloController 进行测试我们自己的写的接口 RestController public class HelloController {AutowiredHelloService helloService;RequestMapping(/hello)public String hello(){return helloService.sayHello(zxc);}} 编写配置文件 application.properties demo.hello.prefixMystarter-perfix-- demo.hello.suffix--Mystarter-suffix 启动项目进行测试结果成功
http://www.hkea.cn/news/14472612/

相关文章:

  • 福建人力资源建设网站家装装修风格大全
  • 温州建设局网站林南飞c网站建设
  • 关于集团网站建设的请示wordpress设置浏览数
  • 网站托管的好处wordpress 问卷
  • 苏州建设建设信息网站苏州市住建局官方网站
  • 鹤岗手机网站建设企业工商注册查询
  • 网站建设一般需要多久网站设计标语
  • 为什么选php语言做网站找人做网站要准备什么
  • 上海网站建设制作深汕特别合作区属于深圳吗
  • 网络营销推广的模式包括邯郸网站建设优化排名
  • 长尾词挖掘工具爱站网app网站建设宣传方案
  • 英文网站首页优化小学生网站制作
  • 中国免费建站网photoshop免费下载
  • 网络产品推广方案范文东莞网站优化制作
  • app网站建设宣传方案网站推广员如何做
  • 域名申请到网站建设教程广告设计公司经营范围
  • 公司网站的关键词推广怎么做html5网站多少钱
  • 一键网站模块安徽网站推广营销设计
  • 做网站平台赚钱吗网站空间哪家好
  • 网站字体大小选择得物网上商城
  • 公司网站有中文域名吗有了代码如何建设网站
  • 厦门市建设执业资格注册管理中心网站做网站go和php用哪个好
  • 建设网站证深圳软件开发有限公司
  • 海珠电子商务网站建设房山做网站
  • 一个网站做两种产品做招投标有哪些网站
  • 网站建设发展历程小程序商城怎么开发
  • 电子政务和网站建设自评企业网站 自助建站
  • 青海网站建设多少钱wordpress会员微信支付宝
  • 牛商网网站后台网站建设内容介绍
  • 手机棋牌网站大全企业网站建设 建立作用