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

网站开发频道构架谷歌竞价广告

网站开发频道构架,谷歌竞价广告,产品网站建设必要性,外贸英文建站在实际开发中,经常会定义一些公共组件,提供给各个项目团队使用。而在springboot的项目中,一般会将这些公共组件封装为springboot的starter。 1.命名规范 Spring官方Starter通常命名为 spring-boot-starter-{name} 如:spr…

在实际开发中,经常会定义一些公共组件,提供给各个项目团队使用。而在springboot的项目中,一般会将这些公共组件封装为springboot的starter。

1.命名规范

Spring官方Starter通常命名为 spring-boot-starter-{name}
        如:spring-boot-starter-web
Spring官方建议非官方Starter命名应遵循 {name}-spring-boot-starter的格式:
        如 mybatis-spring-boot-starter。

2.首先创建一个SpringBoot基础工程

注意生成启动类pom坐标可以如图位置修改

pom文件如下

  <dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional></dependency></dependencies>

3.创建自动配置类

工程下创建config包,创建UserAutoConfiguratio类

UserAutoConfiguratio代码:


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
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
@ConditionalOnClass(UserService.class)
@EnableConfigurationProperties(UserProperties.class)
public class UserAutoConfiguration {@AutowiredUserProperties userProperties;@Bean@ConditionalOnMissingBean(UserService.class)public UserService userService(){//将userService的字段赋值并注入到ioc容器return new UserService(userProperties.getUserName(), userProperties.getHobby());}
}

这个类作用是读取application.yml的配置属性

4.创建配置类:UserProperties

继续在config包下,创建UserAutoConfiguratio类

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;/*** @author qinbo* @version 1.0* @description: TODO* @date 2025/4/17 23:00*/
@Configuration
@ConfigurationProperties(prefix = "user")
@Data
public class UserProperties {String userName;String hobby;
}

这个类作用是接收yml文件的属性,得到映射

注意yml的写法

user:username: adminhobby: 123456

5.业务类:UserService

继续在config包下,创建UserService类

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;@Data
@AllArgsConstructor
@NoArgsConstructor
public class UserService {String name;String hobby;public String test(){System.out.println("name"+name+"\t\thobby"+hobby);return "this is test method";}
}

这个类就是处理业务

6.创建META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports文件

在resources目录下创建

成功后如下图

这个地方博主掉坑里了/(ㄒoㄒ)/~~

里面编写自动配置类的路径(例如)

com.bo.userstatetr.config.UserAutoConfiguration

最后就是通过clear  install了,把jar包打到本地仓库

现在starter已经打包完成,那么我们如何在另一个boot项目中使用他

(1)导入坐标依赖

这就是之前项目的pom文件

在另一个项目中yml进行配置属性

最后就是依赖注入进行调用

import com.bo.userstatetr.config.UserService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;@SpringBootTest
class ExceldemoApplicationTests {@AutowiredUserService userService;@Testvoid contextLoads() {userService.test();}}

http://www.dtcms.com/wzjs/64620.html

相关文章:

  • 邯郸高端网站建设旺道网站排名优化
  • 招代理九幺seo优化神器
  • 镇江市住房和城乡建设局网站seo优化教程自学网
  • 成都网站建设小程序线上宣传方式有哪些
  • 瑞丽住建局网站个人网站设计图片
  • 网站不提交表单网站制作公司怎么找
  • 建网站 温州今晚赛事比分预测
  • 企业融资数据在哪查百度seo分析工具
  • 锦州网站建设新闻福州seo外包公司
  • 网站后台管理怎么做百度联盟怎么赚钱
  • 咸宁做网站的公司网络营销企业培训
  • 腾龙时时彩做号网站海外推广平台有哪些?
  • 网站备案信息真实性核验单流程深圳品牌策划公司
  • 帮做软件测试的网站优化工具箱
  • wordpress 客服seo基础优化包括哪些内容
  • 做彩票网站是违法吗全网营销方案
  • 两个人能用的一个公司做网站吗新浪舆情通官网
  • 做艺术品展览的网站中国电信视频app下载
  • 北京网站建设推广服百度推广找谁做
  • 导航网站的广告怎么做的百度免费推广平台
  • 怎么申请免费网址温州seo结算
  • 网站空间怎么弄深圳互联网公司50强
  • 永久网站空间打开一个网站
  • 嘉兴建设中学网站大数据培训
  • 国家企业信用公示系统官网(全国)seo站长平台
  • 合肥建站优化高德北斗导航
  • 审查元素 wordpress百度百科优化排名
  • 优化网站排名推广在线教育
  • 成都网页制作公司在线网站seo诊断
  • 工程建设与设计期刊网站邯郸网站seo