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

凡科建站骗子wordpress 统计字数

凡科建站骗子,wordpress 统计字数,外贸网络营销服务,谷歌提交网站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-jdk/  #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();
}//----------------------------------------------------package com.example.demo;import org.springframework.stereotype.Service;@Service
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-jdk模块

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

<project><modelVersion>4.0.0</modelVersion><groupId>com.example</groupId><artifactId>custom-hello-spring-boot-starter-jdk</artifactId><version>1.0.0</version><packaging>pom</packaging><dependencies><!-- 引入自动配置模块 --><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

备注:自动配置注册也可以放到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-jdk</artifactId><version>1.0.0</version>
</dependency>

step2. 配置属性(可选)

custom.hello.message=Hello from Config!

step3.使用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/a/404791.html

相关文章:

  • 贵阳网站建设q.479185700惠建筑人才兼职网
  • 英迈思网站做不下去可以退款吗wordpress无法调用主题布局和图片
  • 用织梦做领券网站广州网站设计出名 乐云践新
  • 怎么查网站死链接做网站金山
  • 微信上微网站怎么做的吗网站建设编写代码问题
  • 网站备案需要什么条件wordpress中文主题排行榜
  • .mil 域名网站有哪些wordpress公共聊天室
  • 网站设计 视频怎么在vmware上做网站
  • wordpress图片标题南京百度提升优化
  • 网站轮播图怎么做WordPress文章百度收录插件
  • 厅门户网站建设昆明建设网站哪家好
  • 衡水做网站优化曲靖seo建站
  • 摄影师做展示的网站小蘑菇网站开发
  • 临沂供电公司网站如何做企业微信
  • 专业的企业网站开发公司网络规划设计师取消了
  • 现在做网站建设挣钱吗网站后台管理系统有哪些
  • 企业网站设计的特点国家建设部查询网站
  • 网站做好是需要续费的吗扬州市城乡建设局网站首页
  • 济南优化推广网站seo网站建设个人职责
  • 网站如何宣传推广wordpress403
  • 手机怎么创建自己的网站平台重庆观音桥
  • 老网站如何做301重定向新网站百度上做网站推广
  • 上传文件到网站根目录手机之家下载安装
  • 效果图网站模板个人养老保险缴费明细
  • 删除 Git 中的历史记录
  • 手机创建网站网站建设需要多少人
  • 免费建设网站抽取佣金宿迁发布最新通告
  • 响应式视频网站网站 图片延时加载
  • 广州网站设计哪家公司好WordPress主题2017
  • vi设计概念seo分析工具有哪些