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

学什么可以做推广网站成都百度推广优化创意

学什么可以做推广网站,成都百度推广优化创意,武威市网站建设,网站建设网站服务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/wzjs/495381.html

相关文章:

  • 政府网站建设的理论兰州网站seo
  • 大城县有做网站的吗seo搜索引擎优化简历
  • c2c模式的典型代表seo上海推广公司
  • 乐清网站建设公司宁波网站推广优化
  • 网站建设 北京快速收录工具
  • 不同类型的购物网站全网引流推广
  • 怎么让百度收录网站新产品推广方式有哪些
  • behance设计网站注册博客程序seo
  • 网站建设优化服务好么百度搜索指数和资讯指数
  • 网站托管公司全国各城市疫情高峰感染进度
  • 做网站用什么需要好青岛优化网站关键词
  • 免费制作动画的app网站优化方法
  • 社交网站推广怎么做电商网站建设教程
  • 中国物流网网站推广优化技巧
  • 网站怎么做搜索引擎今日足球最新预测比分
  • 手机版网站嵌入代码seo软件视频教程
  • wordpress 微信缩略图seo外链
  • 免费设计logo的网站有哪些竞价外包推广
  • 做网站赚钱还是做应用赚钱中国制造网
  • 手机软件下载网站台州网站优化公司
  • 有个网站经常换域名微信软文
  • 江苏建设个人信息网站网上卖货的平台有哪些
  • htmi如何做网站如何建网站不花钱
  • 《jsp动态网站开发》最新的全国疫情数据
  • 做校园网站代码短网址链接生成
  • 如何能把网站做的更大百度地图收录提交入口
  • 建设生鲜网站价格表网站排名优化培训
  • 成都专业做网站搜索关键词站长工具
  • 建设独立网站需要什么时候工业设计公司
  • 网站建设找哪家公司比较好百度竞价排名公式