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

西安做网站哪家比较好网络快速排名优化方法

西安做网站哪家比较好,网络快速排名优化方法,兰州网站推,做博客网站的php代码SpringBoot Starter的介绍参考: Spring Boot Starter简介-笔记-CSDN博客。这里介绍如何自定义一个springBoot Starter。 1. 项目结构 创建一个 Maven 项目,结构如下: custom-spring-boot-starter-demo/ ├── custom-hello-jdk/ # jdk模…

SpringBoot Starter的介绍参考: Spring Boot Starter简介-笔记-CSDN博客。这里介绍如何自定义一个springBoot Starter。

1. 项目结构

创建一个 Maven 项目,结构如下:

custom-spring-boot-starter-demo/
├── custom-hello-jdk/  # jdk模块,包含功能逻辑
├── custom-hello-spring-boot-starter/  #Starter模块

2. 项目代码

2.1 custom-hello-jdk模块

step1. pom.xml

<project><modelVersion>4.0.0</modelVersion><groupId>com.example</groupId><artifactId>custom-hello-jdk</artifactId><version>1.0.0</version><dependencies><!-- Spring Boot 自动配置依赖 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-autoconfigure</artifactId></dependency></dependencies>
</project>

step2. 定义功能接口和实现类

package com.example.demo;public interface HelloService {String sayHello();
}public class DefaultHelloService implements HelloService {private final String message;public DefaultHelloService(String message) {this.message = message;}@Overridepublic String sayHello() {return message;}
}

step3. 配置属性类

使用配置属性类实现属性的灵活绑定:

package com.example.demo;import org.springframework.boot.context.properties.ConfigurationProperties;@Data
@ConfigurationProperties(prefix = "custom.hello")
public class HelloProperties {private String message = "Hello from Custom Starter!";
}

step4. 自动配置类

package com.example.demo;import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;@Configuration
@EnableConfigurationProperties(HelloProperties.class)
public class HelloAutoConfiguration {private final HelloProperties helloProperties;public HelloAutoConfiguration(HelloProperties helloProperties) {this.helloProperties = helloProperties;}@Bean@ConditionalOnMissingBean(HelloService.class)public HelloService helloService() {return new DefaultHelloService(helloProperties.getMessage());}
}

2.2 custom-hello-spring-boot-starter模块

step1.pom.xml添加对custom-hello-jdk的依赖

<project><modelVersion>4.0.0</modelVersion><groupId>com.example</groupId><artifactId>custom-hello-spring-boot-starter</artifactId><version>1.0.0</version><packaging>pom</packaging><dependencies><!-- 引入jdk模块 --><dependency><groupId>com.example</groupId><artifactId>custom-hello-jdk</artifactId><version>1.0.0</version></dependency></dependencies>
</project>

step2.注册自动配置

在 src/main/resources/META-INF/spring.factories 中添加:

org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.example.demo.HelloAutoConfiguration

备注:spring.factories文件也可以放到custom-hello-jdk模块里,在starter里仅放pom文件,作为依赖聚合,方便用户引入。

step3.构建和发布

  1. 执行 mvn clean install 将 Starter 安装到本地 Maven 仓库
  2. 或通过 mvn deploy 发布到远程仓库

2.3 使用自定义 Starter

背景:在另外一个项目中使用自定义的Starter。

step1. 在另一个 Spring Boot 项目中引入依赖

<dependency><groupId>com.example</groupId><artifactId>custom-hello-spring-boot-starter</artifactId><version>1.0.0</version>
</dependency>

step2. 配置属性(可选)

若不配置,则使用HelloProperties中设置的默认值:

custom.hello.message=Hello from Config!

step3.使用Bean

可直接使用@Autowired引入目标bean:

import com.example.demo.HelloService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;@RestController
public class HelloController {@Autowiredprivate HelloService helloService;@GetMapping("/hello")public String hello() {return helloService.sayHello();}
}

2.4 总结

上述自定义springBoot Starter的完整流程说明:

  1. jdk功能模块:包含实际功能代码、配置属性等
  2. Starter 模块:作为依赖聚合,方便用户引入
  3. 条件化配置:通过 @ConditionalOnMissingBean 避免重复 Bean
  4. 属性绑定:使用 @ConfigurationProperties 实现灵活配置
http://www.dtcms.com/wzjs/318222.html

相关文章:

  • 玄武模板网站制作点击查看福州百度代理
  • 深圳品牌男装有哪些seo做得比较好的企业案例
  • 在一个网站下建设多个子网站怎样打百度人工客服热线
  • 上海网站建设代码seo刷排名工具
  • 做网站安卓客户端百度帐号登录入口
  • 做网站怎么分手机版和电脑版重庆seo扣费
  • 网站学做糕点的课程百度云搜索引擎入口百度网盘
  • 合肥市房产信息网官网北京搜索优化排名公司
  • 泉州建设企业网站磁力宅
  • 关于网站建设中原创文章的一些想法永久免费域名申请
  • 公司网站建设的分类互联网推广方式有哪些
  • 制作网页完整步骤手机版seo实战培训中心
  • 十堰建设银行官方网站能打开各种网站的搜索引擎
  • 宿迁建设企业网站电脑培训速成班多少钱
  • 优惠建网站hyein seo
  • 郑州制作网站哪家好seo1短视频网页入口营销
  • 内蒙古最新消息今天四川seo整站优化费用
  • 北京市住房建设委员会门户网站口碑营销的成功案例
  • 政府网站互动回应板块建设企业网站的功能
  • 推广公司简介推广资源seo
  • 出售东西的网站怎么做网站推广计划
  • 嘉兴高端建站公司公司网站seo外包
  • 设计b2c网站建设广州市网络seo外包
  • 长宁做网站公司seo排名哪家公司好
  • 免费空间说说点赞seo排名是什么
  • 本地电脑静态网站建设进入百度搜索网站
  • 网站建设服务合同交印花税郑州网站排名优化公司
  • 网站内容如何编辑百度收录技术
  • 做计划的网站seo岗位有哪些
  • 网站怎么做json数据库口碑营销什么意思