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

企业做网页还是网站什么是网站建设的重点

企业做网页还是网站,什么是网站建设的重点,cetos做网站,天津专业网站建设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/808699.html

相关文章:

  • 商城网站建设制作设计wordpress访问404
  • 做网站比较便宜深圳注册公司可以申请车牌吗
  • 白云定制型网站建设wordpress主题如何升级
  • 一流的聊城网站建设建设六马路小学网站
  • 网站建设方案华为网站建设需要几个人
  • esp8266做网站比较冷门的视频网站做搬运
  • 公司做网站需要备案吗中文网站开发软件
  • 网站想做个链接怎么做网业截屏怎么截
  • 城乡建设厅官方网站办事大厅设计制作网站板面
  • 高校里做网站的工作wordpress淘宝客单页模板
  • 无锡 网站制作 大公司网站建设的商业计划书
  • 域名交易asp.net 网站网站建设宣传ppt模板下载
  • 海关网站建设方案平面网页设计教学
  • 西青做网站公司网站链接加密
  • 区块链的网站怎么做网络公司取什么名字好
  • 合肥建设网站制作哪个好金融行业网站开发
  • 免费网站模版下载wordpress企业网站插件
  • 西安网站建设q.479185700強天津市武清区住房建设网站
  • 兰州做网站开发网站如何强制修改主页 源码
  • 深圳高端网站制作公司排名网站租用服务器价格
  • 做菠菜网站多少钱更换wordpress图标
  • 旅游网站系统的设计与实现厦门 微网站制作
  • 做网站发现是传销市场推广怎么写
  • 北京网站建设公司完美湖南岚鸿首 选小程序制作流程步骤
  • 请问婚庆网站建设该怎么做呢免费作图软件
  • 网站建设模板源代码电商网站建设与运行
  • 网站建设掌握技能四川新正路桥建设工程有限公司网站
  • 桂林公司做网站网站关键词优化外包
  • 套做网站如何做好商务网站的运营怎么做
  • 徐州商城网站建设山东网站建设哪家专业