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

长沙建设工程造价网站网站 ip修改备案流程

长沙建设工程造价网站,网站 ip修改备案流程,门户网站制作哪专业,无锡模板建站源码声明:原文作者:yuan_404 文章目录1. 说明2 . 编写启动器3 . 新建项目测试自己写的启动器1. 说明 启动器模块是一个 空 jar 文件,仅提供辅助性依赖管理,这些依赖可能用于自动装配或者其他类库 命名归约: 官方命名&…
  • 声明:原文作者:yuan_404

文章目录

  • 1. 说明
  • 2 . 编写启动器
  • 3 . 新建项目测试自己写的启动器

1. 说明

  • 启动器模块是一个 空 jar 文件,仅提供辅助性依赖管理,这些依赖可能用于自动装配或者其他类库

命名归约:

  • 官方命名:

    • 前缀:spring-boot-starter-xxx
    • 比如:spring-boot-starter-web…
  • 自定义命名:

    • xxx-spring-boot-starter
    • 比如:mybatis-spring-boot-starter

2 . 编写启动器

  1. 在IDEA中新建一个空项目 spring-boot-starter-diy

  2. 新建一个普通Maven模块:demo-spring-boot-starter

  3. 新建一个Springboot模块:demo-spring-boot-starter-autoconfigure

  4. 点击apply即可,基本结构

  5. 在starter 中 导入 autoconfigure 的依赖

    <!-- 启动器 -->
    <dependencies><!--  引入自动配置模块 --><dependency><groupId>com.demo</groupId><artifactId>demo-spring-boot-starter-autoconfigure</artifactId><version>0.0.1-SNAPSHOT</version></dependency>
    </dependencies>
  6. 将 autoconfigure 项目下,Pom中加入依赖

     <dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-configuration-processor</artifactId><optional>true</optional></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-autoconfigure</artifactId></dependency>
    </dependencies>

    说明:
    第一个依赖 主要是为编译器配置的 可以根据properties 鼠标右键 点到用这个属性的类上个

    第二个依赖 主要是为了自动装配

  7. 编写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注解的作用就是读取配置文件指定属性的值

  8. 编写一个自己的服务

    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();}
    }
  9. 编写自动配置类并注入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的时候才进行下一步

  10. 在resources编写一个自己的 META-INF\spring.factories

```java
# Auto Configure
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.demo.config.HelloServiceAutoConfiguration```
  1. 编写完成后,可以安装到maven仓库中

  2. 项目包结构

3 . 新建项目测试自己写的启动器

  1. 新建一个SpringBoot 项目(需要引入 web 的启动器)

  2. 导入我们自己写的启动器

    <dependency><groupId>com.demo</groupId><artifactId>demo-spring-boot-starter</artifactId><version>1.0-SNAPSHOT</version>
    </dependency>
  3. 编写一个 HelloController 进行测试我们自己的写的接口

    @RestController
    public class HelloController {@AutowiredHelloService helloService;@RequestMapping("/hello")public String hello(){return helloService.sayHello("zxc");}}
  4. 编写配置文件 application.properties

    demo.hello.prefix="Mystarter-perfix--"
    demo.hello.suffix="--Mystarter-suffix"
  5. 启动项目进行测试,结果成功

http://www.yayakq.cn/news/433747/

相关文章:

  • qq网页版 登陆太原企业网站seo
  • 二手东西网站怎么做建站宝盒v8破解版下载
  • 百度站长平台推出网站移动化大赛常州建设局下属网站
  • 中国建设布网站代理注册公司哪家好
  • 深圳企业公司做网站自己做网站的方法
  • 服务网站建设企业网址大全下载安装
  • 株洲专业建设网站wordpress 花生壳
  • 微网站不能分享朋友圈dw网页制作怎么设置背景颜色
  • 焦作网站建设费用seo信息网
  • 有哪些公司网站关键词优化排名技巧
  • 陕西省建设厅证网站号多少小程序加盟代理平台
  • 深圳网站建设 案例微信公众号小说网站怎么做
  • 广州专业网站制作平台广西南宁网站制作
  • 农村电子商务网站建设方案建e室内设计网 周婷
  • 公司网站做好了怎么做排名青岛工程建设管理信息网站
  • 免费的外贸网站推广方法西乡网站建设
  • 江苏省建设执业中心网站成都建设厅官方网站
  • 怎么制作网站源码盐城优化办
  • 企业展示网站模板酒店如何进行网络营销
  • 淘宝指数网址网站 百度 关键字优化
  • 赣州 做网站网站改版多久恢复
  • 做js题目的网站排名优化工具下载
  • 8网站建设做网站网站系统怎么建设
  • 网站的栏目关键词做的网站底部应该标注什么
  • 沧州网络运营中心电话seo网站推广seo
  • 网站建设公司需要具备台州椒江做网站
  • 网站后端模板长沙seo
  • 海外网站服务器网址两个域名同时指向一个网站
  • 做网站遇到竞争对手怎么办wordpress内存不足
  • 如何做网站长尾关键词布局网站建设合同的主要内容