当前位置: 首页 > 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/  #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/60647.html

相关文章:

  • 互联网创业平台有哪些济南做seo的公司排名
  • 网站建设定制单中国搜索引擎排行榜
  • 长沙网站建设zh68百度浏览器官网下载
  • 极速时时彩网站建设平台推广是什么意思
  • 福建建设注册中心网站广州广告推广公司
  • 网站如何申请域名网络推广公司官网
  • 企业做门户网站的重要性关键词挖掘方法
  • 网站建设费用的账务处理网络营销的特点
  • 万网备案网站名称成都网站建设团队
  • 如何引用网站上的资料做文献外贸接单十大网站
  • 南昌科技网站建设我想做地推怎么找渠道
  • 网站建设架构济南seo优化公司
  • 开办网站需要什么手续网站关键词在线优化
  • 做网站的公司排行班级优化大师网页版登录
  • 学敏网站建设宁德市住房和城乡建设局
  • 广州云建站模板爱战网官网
  • 什么公司做网站最好服务网站排名咨询
  • 网站建设销售兼职合同百度免费下载安装
  • wamp做网站seo需要掌握什么技能
  • 丰台网站关键词优化精准信息300099
  • 西宁市住房和城乡建设局网站免费的网络推广渠道有哪些
  • 万网如何上传静态网站网络营销的推广
  • 纯静态网站 后台苏州seo快速优化
  • 服装设计网页搜索引擎优化是指什么意思
  • 福步外贸人才网seo网络推广员招聘
  • 网站设计规划书郑州专业网站建设公司
  • ip在线代理网页南宁seo主管
  • 网站管理一般要做什么外链seo招聘
  • 专注武汉手机网站设计seo试用软件
  • 一个人做运营网站深圳网站建设专业乐云seo