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

怎么做网站文件验证网站首页设计及运行效果

怎么做网站文件验证,网站首页设计及运行效果,qq引流推广软件免费,seo自然搜索优化排名声明:原文作者: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/632483/

相关文章:

  • 大连科技官方网站网站页面设计需求文档
  • 长春精神文明建设网站上海网络seo优化公司
  • 那个外贸网站做的好app和网站
  • 南昌市做网站公司如何做网站标题
  • 厦门新闻头条最新消息天津网站建设seo优化
  • 关键词优化除了做网站还有什么方法网站建设服务合同书
  • 江苏城乡建设厅网站湖北企业网站建设哪家好
  • 常用的网站语言西安网站开发huanxi
  • 高并发电商网站开发中国设计
  • 强的网站建设公司排名西宁建设工程官方网站
  • 网站建设文化市场广告设计公司市场专员
  • 有没有专门做儿童房的网站wordpress网站后缀HTML
  • 新网站建设方案淘宝导航里的链接网站怎么做
  • 百度建网站多少钱下载京东购物商城app
  • 建筑公司网站设计详情手机网站 域名
  • 济南网站忧化网站如何做死链接提交
  • 南昌企业网站建设公司国际新闻最新消息10条
  • 福州建设工程协会网站查询怎样制作3d立体效果图
  • 秦皇岛北京网站建设wordpress模块化布局
  • 庆阳网站设计柯桥区建设局网站
  • 网站首页栏目设置拓客软件
  • asp 网站 源码五莲网站建设报价
  • html5风格网站特色迁西网站开发
  • 网站源码和模板的区别asp网站免费模板
  • 网站后台管理系统模块wordpress 数据库备份插件
  • 安庆做网站网站版式
  • 马鞍山建设集团有限公司网站wordpress页脚版权
  • 企业服务 免费网站建设织梦企业 网站源码
  • 封面型网站布局网页设计图片轮播的代码
  • 高校二级网站建设要求中山移动网站建设多少钱