我们最早配置spring应用的时候,必须要经历的步骤:1.pom文件中引入相关的jar包,包括(🕰)spring,redis,jdbc等等 2.通过properties或者xml配置相关的信息 3.不断调试直到可以使用。 问题:时间(👢)长,复杂,同时在写下一个项(🥪)目的时候大概率要经过相同的模式配置才能达到可以使用的状态。同时在众多的jar中,我们需要相(⏩)互配置依赖间的版本关系,十分的复杂 原始版本: 我们就想到能不能把这些(😌)jdbc整合起来,类似于深度(🔸)学习中anaconda下载依赖一样去管理,依赖(🚀)间的关系不需要我们去负责,而是交给spring去管理。 starter版本: 我们(🤵)可以将starter包看作是一个包装箱,把复杂的事情都交给了spring负责,官方维护starter包会导(😮)入(🛡)的东西。而我们只需要知道那个starter包是有什么用处,例如:spring-boot-starter-web是负(🙎)责spring web项目的依赖。 starter文件也只是一个pom文件,而不是jar,它的目(🍈)的也是去(🐧)自动的引入其他的jar文件,上(🕍)图展示的(🐑)spring-boot-starter-web中的依赖就(☕)有spring-boot-starter。 starter只是一个pom文件 下面也就是starter的关(🎷)键所在,请问我们为(🕦)什么引入了(🔂)starter之后只需要配置一点点的个性化(♍)设置,例如创建application.properties仅仅配置端口等等(🗣)就可以完成(📣)启动应用?是谁帮助我们配置了其他复杂的信息? 引出自动配置 自动配(⛓)置主要通过xxxAutoConfiguration这些类来实现,我们查找一个这样的类来进行示例演示 上图是DataSourceAutoConfiguration这个自动配置类,我们可以看到类上的几(🔧)个注解(😒)。 我们点击@EnableConfiguration注解中的@DataSourceProperties进去查看 可以查看(🏨)到这里使用@configurationPropertes,@ConfigurationProperties注解的作用是把yml或者properties配置文件转化为bean。 同时这里也设置了prefix前缀,在我们项目的application.properties中配置的时候,提示的就(🏵)是这些bean实例中的属性。 所以是使用@ConfigurationProperties和@EnableConfigurationProperties这两个注解来完成将一个包含众多(🎮)属性的类来注册成为可供springIoc容(🌃)器管理的bean。 而这个bean的注册过程是在各个XXXAutoConfiguration类中完成的。 我们都知道springboot默认扫描启动类(🚩)下面的主类和子类的bean来完(⏲)成注解,但是并没有包括依赖包中的类,那么依赖包中的bean是如何被发现和加载的? 关键(🙋)在于@SpringBootApplication这个注解 注解层次: 注解层次图示:(🆗) 如(💱)果要让一个普通类(🛄)交(🐣)给Spring容器管理,通常有以下方法: springboot中使用了(🥧)@Import 方法 @EnableAutoConfiguration注解中使用了(🚖)@Import({AutoConfigurationImportSelector.class})注(🗄)解,AutoConfigurationImportSelector实现了DeferredImportSelector接(❌)口, DeferredImportSelector接口继承了ImportSelector接口(💀),ImportSelector接口只有一个(♍)selectImports方法。 selectImports方法返回一组bean,@EnableAutoConfiguration注解借助@Import注解将这(🏁)组bean注入到spring容(🚠)器中,springboot正式通(😒)过这种机制来完(🥀)成bean的注入的。 关于@import注解的加载可以查看这个文章:https://zhuanlan.zhihu.com/p/147025312 ps:晕乎乎的,我只看懂了(🤬)一部分。 加载redisAutoConfiguration的流程图示 下面我们演示自定义starter的流程: 我们确定好自定义starter的GAV(groupId,ArtifactId,Version),这里需要注意的是ArtifactId的命名,对于spring进行管理的starter包,命名规则是:spring-boot-starter-xxx,而为(🚇)了区别spring进行管理的starter包,自定义的starter包一般命名规则是:xxx-spring-boot-starter,例如mybatis官方推出的starter包:mybatis-spring-boot-starter。 groupId使用自己域名(💙)的反写(🎤)即可。 项目(🕚)结(🐱)构如下: 依赖:spring-boot-configuration-processor 作用:导入之后会自(🤨)动生成元数据(meta-data),在application.properties配置的时候会有提示。 例如(👔): 由(🐻)于是自动生成,在你配置了@ConfigurationProperties之后就会自动生成元数据,在你(🌗)写application.properties的时候就会进行自动提示。 当无法提示的时候多次clean,之后再compile然(💑)后在install发布。 具体可以看这个博客 https://blog.csdn.net/wangleleb/article/details/104904348 依赖: spring-boot-starter 作用:(⛔)是为了使用(🖊)前面提到的自动配置的注解。注解@ConfigurationProperties和@EnableConfigurationProperties两(🏒)个(🤞)注解都在spring-boot-context包中 编写自动配(🏹)置类代码: 编写service代码:(🏏) 编写config类: 关于这里@ConditionOnProperty这个注解,该注解的大概含义就是,对于前缀是demo的属性,底下的值isopen为true时候,该自动配置类才会生效。 编写spring.factories 将key:EnableAutoConfiguration-->DemoConfig这个类 使用maven命令:mvn clean compile install 清理,编译,发布到本地仓库中去 配置资源文件 随便编写一个类验证 结果<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>
二.starter内部详情 <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-configuration-processor</artifactId> <version>2.7.3</version> <optional>true</optional> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> <version>2.7.1</version> <optional>true</optional> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.24</version> </dependency> </dependencies>
package properties; import lombok.Getter;import lombok.Setter;import org.springframework.boot.context.properties.ConfigurationProperties; @ConfigurationProperties(prefix = "demo")@Getter@Setterpublic class DemoProperties{ private String var1; private String var2; }
package service; import lombok.AllArgsConstructor; @AllArgsConstructorpublic class DemoService { public String var1; public String var2; public String variable(){ return this.var1 + " " + this.var2; } }
@Configuration@EnableConfigurationProperties(DemoProperties.class)// 只有当name的值与havingValue的值(♿)相同的时候加载@ConditionalOnProperty( prefix = "demo", name = "isopen", havingValue = "true")public class DemoConfig { @Resource private DemoProperties demoProperties; @Bean public DemoService demoService(){ return new DemoService(demoProperties.getVar1(),demoProperties.getVar2()); }}
<!--引入我(🗝)写的starter--><dependency> <groupId>org.oldoldcoder</groupId> <artifactId>oldoldcoder-spring-boot-starter</artifactId> <version>1.0-SNAPSHOT</version></dependency>
# 使用自己写的starterdemo.isopen=truedemo.var1=var1demo.var2==var2
@Componentpublic class TestService { @Resource private DemoService demoService; @PostConstruct public void test(){ System.out.println("你好"+demoService.variable()); }}
1.请问哪个网站可以免费在线观看动漫《能看的不卡的AV片》?
优酷视频网友:http://www.ahxhhy.com/video/151156223.html
2.《能看的不卡的AV片》是什么时候上映/什么时候开播的?
腾讯视频网友:上映时间为2022年,详细日期可以去百度百科查一查。
3.《能看的不卡的AV片》是哪些演员主演的?
爱奇艺网友:能看的不卡的AV片演员表有,导演是。
4.动漫《能看的不卡的AV片》一共多少集?
电影吧网友:目前已更新到全集已完结
5.手机免费在线点播《能看的不卡的AV片》有哪些网站?
手机电影网网友:美剧网、腾讯视频、电影网
6.《能看的不卡的AV片》评价怎么样?
百度最佳答案:《能看的不卡的AV片》口碑不错,演员阵容强大演技炸裂,并且演员的演技一直在线,全程无尿点。你也可以登录百度问答获得更多评价。
Copyright © 2008-2024