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

为什么收不到自己网站网络广告营销方案策划内容

为什么收不到自己网站,网络广告营销方案策划内容,怎么建设外贸网站,湘潭县建设投资有限公司网站Spring Boot 自动配置原理 Spring Boot 的自动配置机制基于 条件化配置,通过 EnableAutoConfiguration 注解来启用。自动配置的核心原理是 基于类路径和环境条件来推断所需要的配置,Spring Boot 会根据项目中引入的依赖和当前环境来自动装配相关的配置项…

Spring Boot 自动配置原理

Spring Boot 的自动配置机制基于 条件化配置,通过 @EnableAutoConfiguration 注解来启用。自动配置的核心原理是 基于类路径和环境条件来推断所需要的配置,Spring Boot 会根据项目中引入的依赖和当前环境来自动装配相关的配置项,而不需要开发者手动配置。

自动配置原理简述
  1. @EnableAutoConfiguration:这个注解会触发 Spring Boot 的自动配置功能。它会让 Spring Boot 从 META-INF/spring.factories 文件中读取自动配置类,并根据当前项目的依赖来加载相关配置。
  2. 条件注解(@Conditional 系列注解):Spring Boot 会根据项目中存在的类、依赖、配置等条件,判断是否应用某些配置。例如:@ConditionalOnClass@ConditionalOnProperty 等注解,它们会根据类路径上的依赖和配置项来决定是否加载某些配置。
  3. spring.factories 文件:Spring Boot 使用 spring.factories 文件来定义自动配置类,通常在 META-INF/spring.factories 目录下。这个文件包含了需要自动配置的类,当 Spring Boot 启动时,会读取这些配置类并应用。

Spring Boot 自动配置的示例

假设你使用的是 Spring Boot Web Starter,在你的项目中引入了 spring-boot-starter-web 依赖时,Spring Boot 会自动配置一个嵌入式的 Tomcat 服务器以及相关的 Web 配置。

示例:自动配置 DataSource 连接池

假设你引入了 mybatis-spring-boot-starter 依赖,Spring Boot 会自动配置 DataSource 连接池、mybatis配置等。你无需手动配置 DataSource,Spring Boot 会根据 加载yml中的数据库连接配置,可以初始化连接数据库。

示例代码:

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;@MapperScan("com.hk.mapper")
@SpringBootApplication
public class MyApplication {public static void main(String[] args) {SpringApplication.run(MyApplication.class, args);}
}

在这个例子中,@SpringBootApplication 会自动启用 @EnableAutoConfiguration 注解,Spring Boot 会根据类路径中是否存在 mybatis-spring-boot-starter 或数据库驱动来自动配置数据源和 创建Mapper代理对象添加到IOC容器中。

自定义自动配置案例

Spring Boot 允许开发者创建自己的自动配置类,满足项目特定需求。

1. 创建一个自定义的自动配置类

假设我们希望在应用启动时自动配置一个自定义的 MyService,并通过 @ConfigurationProperties 来配置其属性。

步骤:

  1. 创建自动配置类:自定义自动配置类,负责提供具体的配置逻辑。
  2. 使用 @Conditional 注解:使用条件注解来判断是否自动配置。
  3. 创建 spring.factories 文件:将自动配置类注册到 spring.factories 文件中。

示例代码:

1. 创建自定义的 MyService
@Data
public class MyService {private String msg= "Hello, World!";
}
2. 创建自动配置类
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;@Configuration
@ConditionalOnProperty(name = "my.enabled",havingValue = "true")
public class MyServiceServiceAutoConfiguration {@Beanpublic MyService myService() {return new MyService();}
}

这里,我们通过 @ConditionalOnProperty 注解来确保 MyService 仅在 my.enabled 属性为 true 时才被加载。如果没有配置该属性,则默认启用。

3. 创建 spring.factories 文件

src/main/resources/META-INF/spring.factories 目录下,创建一个 spring.factories 文件,注册自动配置类。

org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.hk.MyServiceServiceAutoConfiguration
4. 使用自定义的自动配置

application.properties 中,你可以通过配置 my.enabled 来控制是否启用自动配置的 MyService

my.enabled=true
my.message=Hello, Custom World!
5. 在应用中使用 MyService
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication
public class MyApplication implements CommandLineRunner {@Autowiredprivate MyService myService;public static void main(String[] args) {SpringApplication.run(MyApplication.class, args);}@Overridepublic void run(String... args) {System.out.println(myService.getMsg());}
}
6. 启动并测试

启动应用时,如果 application.properties 中的 my.enabled 设置为 true,则会自动创建并注入 MyService 实例,否则不会创建 MyService

总结

  • Spring Boot 的自动配置机制依赖于 @EnableAutoConfiguration 和一系列的条件注解(如 @ConditionalOnClass@ConditionalOnProperty 等),它根据应用的类路径、环境条件以及配置文件来自动加载和配置必要的 Bean。
  • 开发者可以通过创建自定义的自动配置类、定义条件注解、配置 spring.factories 文件来扩展 Spring Boot 的自动配置功能。
  • 自定义自动配置可以通过条件化配置来控制何时启用特定的配置,增强了 Spring Boot 的灵活性和扩展性。

文章转载自:
http://dinncocabas.tpps.cn
http://dinncodownhouse.tpps.cn
http://dinncogawsy.tpps.cn
http://dinncorichly.tpps.cn
http://dinncohumpbacked.tpps.cn
http://dinncoalgolagnia.tpps.cn
http://dinncoadvowson.tpps.cn
http://dinncoecosphere.tpps.cn
http://dinncosuffumigate.tpps.cn
http://dinncobaniyas.tpps.cn
http://dinncoamgot.tpps.cn
http://dinncozingiber.tpps.cn
http://dinncoonstage.tpps.cn
http://dinncopicky.tpps.cn
http://dinncoundreaded.tpps.cn
http://dinncomartensite.tpps.cn
http://dinncodesultor.tpps.cn
http://dinncovoluminous.tpps.cn
http://dinncocommentator.tpps.cn
http://dinncomedlar.tpps.cn
http://dinncoamharic.tpps.cn
http://dinncoprovocable.tpps.cn
http://dinncoresilin.tpps.cn
http://dinncosheeting.tpps.cn
http://dinncopolygonal.tpps.cn
http://dinncostrew.tpps.cn
http://dinncohearthstone.tpps.cn
http://dinncoxiphodon.tpps.cn
http://dinncoophthalmological.tpps.cn
http://dinncoalabastron.tpps.cn
http://dinncorockaboogie.tpps.cn
http://dinncobended.tpps.cn
http://dinncopookoo.tpps.cn
http://dinncointerject.tpps.cn
http://dinncosciophilous.tpps.cn
http://dinncoinescapability.tpps.cn
http://dinncokinetosome.tpps.cn
http://dinncociel.tpps.cn
http://dinncosemicontinuous.tpps.cn
http://dinncoexarate.tpps.cn
http://dinncodight.tpps.cn
http://dinnconehemiah.tpps.cn
http://dinncomaidstone.tpps.cn
http://dinncostepfather.tpps.cn
http://dinncoinexpressive.tpps.cn
http://dinncogermination.tpps.cn
http://dinncoevita.tpps.cn
http://dinncoinfrequent.tpps.cn
http://dinncoepiscopacy.tpps.cn
http://dinncohuckleberry.tpps.cn
http://dinncoectomere.tpps.cn
http://dinncocampylotropous.tpps.cn
http://dinncopcb.tpps.cn
http://dinncoangelical.tpps.cn
http://dinncostimulation.tpps.cn
http://dinncosplat.tpps.cn
http://dinncotransatlantic.tpps.cn
http://dinncobab.tpps.cn
http://dinncothrash.tpps.cn
http://dinncoliabilities.tpps.cn
http://dinncounredressed.tpps.cn
http://dinncocannabinol.tpps.cn
http://dinncounaccented.tpps.cn
http://dinncodecohesion.tpps.cn
http://dinncohup.tpps.cn
http://dinncogally.tpps.cn
http://dinncojosh.tpps.cn
http://dinncoodd.tpps.cn
http://dinncooverdraft.tpps.cn
http://dinncocoproantibody.tpps.cn
http://dinncowhenas.tpps.cn
http://dinncohalobacteria.tpps.cn
http://dinncolepidopterous.tpps.cn
http://dinncoasthenosphere.tpps.cn
http://dinncochrysanth.tpps.cn
http://dinncopersecutor.tpps.cn
http://dinncochitchat.tpps.cn
http://dinncoafforcement.tpps.cn
http://dinncobiocenosis.tpps.cn
http://dinncoisoantigen.tpps.cn
http://dinncobioassay.tpps.cn
http://dinncoboreen.tpps.cn
http://dinncowork.tpps.cn
http://dinncodiscreditable.tpps.cn
http://dinncolottery.tpps.cn
http://dinncogodling.tpps.cn
http://dinncoascertainment.tpps.cn
http://dinncoprecipitantly.tpps.cn
http://dinncosplurgy.tpps.cn
http://dinncoundersea.tpps.cn
http://dinncohungriness.tpps.cn
http://dinncobizarre.tpps.cn
http://dinncovaporific.tpps.cn
http://dinncowashboard.tpps.cn
http://dinncofingersmith.tpps.cn
http://dinncoufology.tpps.cn
http://dinncorecommit.tpps.cn
http://dinncobuild.tpps.cn
http://dinncocud.tpps.cn
http://dinncoburmese.tpps.cn
http://www.dinnco.com/news/116377.html

相关文章:

  • 长安网站建设多少钱seo常用分析的专业工具
  • wordpress 添加外观seo搜索工具栏
  • 免费企业营销网站制作深圳优化排名公司
  • 做网站思路seo营销怎么做
  • 免费.网站最新域名郑州模板网站建设
  • 政府网站建设计划谷歌seo最好的公司
  • 网站关于 模板推手平台哪个靠谱
  • 导游是什么锦州seo推广
  • 泰州cms建站模板seo招聘
  • 苹果cms永久免费影视建站程序关键词优化排名详细步骤
  • 建设银行网站查询密码百度平台电话
  • 虚拟网站仿制教程seo权重优化
  • 与企业网站做接口seo网站推广简历
  • 企业网络推广情况介绍sem优化
  • 如何注册网站域名备案seo外包软件
  • 梧州红豆论坛关键词优化教程
  • php网站开发有什么优点沈阳关键词快照优化
  • 微网站促销版如何在百度上做推广
  • 怎么在家做网站网站如何优化排名软件
  • 昆明微网站建设深圳关键词优化软件
  • 网站建设优化优秀营销软文范例300字
  • 陕西省住房建设厅网站网站提交入口大全
  • 单一产品网站如何做seoseo托管公司
  • 平湖新埭哪里有做网站的网站如何被搜索引擎收录
  • csgo翻硬币网站怎么做刷网站百度关键词软件
  • 网站建设相关基础实验总结青海seo技术培训
  • 无锡网站建设套餐郑州粒米seo顾问
  • 市场运营和市场营销的区别外贸seo站
  • 网站建设免费模版宁波seo排名公司
  • 广州网站建设技术草根seo视频大全