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

做游戏网站主页的素材百度竞价排名榜

做游戏网站主页的素材,百度竞价排名榜,北京蓝杉网站建设公司,wordpress图片翻页ConfigurationProperties注解通常用于将外部配置文件(如application.properties或application.yml)中的属性映射到Java类中。它通常加在类上,但也可以加在方法上。加在方法上时,通常与Bean注解一起使用,以便将配置属性…

@ConfigurationProperties注解通常用于将外部配置文件(如application.propertiesapplication.yml)中的属性映射到Java类中。它通常加在类上,但也可以加在方法上。加在方法上时,通常与@Bean注解一起使用,以便将配置属性注入到Spring容器中的Bean中。

示例:将@ConfigurationProperties加在方法上

以下是一个完整的示例,展示如何将@ConfigurationProperties注解加在方法上,并将配置属性注入到Spring容器中的Bean中。

1. 创建配置属性类

首先,创建一个简单的配置属性类,用于映射外部配置文件中的属性。

import org.springframework.boot.context.properties.ConfigurationProperties;@ConfigurationProperties(prefix = "app")
public class AppProperties {private String name;private String version;// Getters and Setterspublic String getName() {return name;}public void setName(String name) {this.name = name;}public String getVersion() {return version;}public void setVersion(String version) {this.version = version;}
}
2. 创建配置类

创建一个配置类,并在方法上使用@ConfigurationProperties注解和@Bean注解。

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;@Configuration
@EnableConfigurationProperties
public class AppConfig {@Bean@ConfigurationProperties(prefix = "app")public AppProperties appProperties() {return new AppProperties();}
}
3. 配置文件

application.propertiesapplication.yml文件中添加配置属性。

application.properties
app.name=MyApp
app.version=1.0.0
application.yml
app:name: MyAppversion: 1.0.0
4. 使用配置属性

在你的应用程序中,你可以通过注入AppProperties来使用这些配置属性。

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;@Service
public class AppService {private final AppProperties appProperties;@Autowiredpublic AppService(AppProperties appProperties) {this.appProperties = appProperties;}public void printAppProperties() {System.out.println("App Name: " + appProperties.getName());System.out.println("App Version: " + appProperties.getVersion());}
}
5. 运行应用

在你的应用程序中调用AppServiceprintAppProperties方法来打印配置属性。

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;@Component
public class AppRunner implements CommandLineRunner {private final AppService appService;@Autowiredpublic AppRunner(AppService appService) {this.appService = appService;}@Overridepublic void run(String... args) throws Exception {appService.printAppProperties();}
}

总结

  • 配置属性类:创建一个简单的类,用于映射外部配置文件中的属性。
  • 配置类:在方法上使用@ConfigurationProperties注解和@Bean注解,将配置属性注入到Spring容器中的Bean中。
  • 配置文件:在application.propertiesapplication.yml文件中添加配置属性。
  • 使用配置属性:通过注入配置属性类来使用这些配置属性。

在Spring框架中,@Autowired 注解通常用于自动注入依赖。虽然它通常用于类的字段或构造函数上,但也可以用于方法参数上。@Autowired 加在形参上的用法也是合法的,并且可以与 @Qualifier 注解一起使用,以指定具体的bean。

以下是一个示例,展示了如何在方法参数上使用 @Autowired@Qualifier 注解:

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.kafka.core.KafkaProperties;
import org.springframework.stereotype.Service;@Service
public class KafkaService {private final KafkaTemplate<String, String> kafkaTemplate;private final KafkaProperties kafkaProperties;@Autowiredpublic KafkaService(KafkaTemplate<String, String> kafkaTemplate,@Qualifier("kafkaProperties") KafkaProperties kafkaProperties) {this.kafkaTemplate = kafkaTemplate;this.kafkaProperties = kafkaProperties;}// 其他方法
}

在这个示例中,KafkaService 的构造函数使用了 @Autowired 注解来自动注入 KafkaTemplateKafkaProperties。其中,KafkaProperties 使用了 @Qualifier 注解来指定具体的bean。

注意:在使用 @Autowired@Qualifier 注解时,确保 Spring 容器中存在相应的bean,并且bean的名称与 @Qualifier 注解中指定的名称匹配。


文章转载自:
http://glutin.jftL.cn
http://homochromatic.jftL.cn
http://misalliance.jftL.cn
http://noesis.jftL.cn
http://rfz.jftL.cn
http://brier.jftL.cn
http://silicula.jftL.cn
http://marlite.jftL.cn
http://infantilism.jftL.cn
http://abuttals.jftL.cn
http://raa.jftL.cn
http://sanatorium.jftL.cn
http://exaggeratory.jftL.cn
http://lilacky.jftL.cn
http://seismotectonic.jftL.cn
http://rabbiter.jftL.cn
http://fth.jftL.cn
http://danaides.jftL.cn
http://plangorous.jftL.cn
http://physiocracy.jftL.cn
http://eversible.jftL.cn
http://cembra.jftL.cn
http://rented.jftL.cn
http://triptane.jftL.cn
http://benchmark.jftL.cn
http://vulcanise.jftL.cn
http://swellfish.jftL.cn
http://quarterstretch.jftL.cn
http://dziggetai.jftL.cn
http://peepbo.jftL.cn
http://nobble.jftL.cn
http://mycologist.jftL.cn
http://urinalysis.jftL.cn
http://shipbreaker.jftL.cn
http://glyptograph.jftL.cn
http://bulldozer.jftL.cn
http://proctoscope.jftL.cn
http://aldosterone.jftL.cn
http://cassino.jftL.cn
http://teleprompter.jftL.cn
http://dandyprat.jftL.cn
http://hemimorphic.jftL.cn
http://althorn.jftL.cn
http://fictionalist.jftL.cn
http://banderole.jftL.cn
http://blastomere.jftL.cn
http://piggy.jftL.cn
http://subterrene.jftL.cn
http://engrave.jftL.cn
http://structuralism.jftL.cn
http://unrig.jftL.cn
http://mensurability.jftL.cn
http://napoli.jftL.cn
http://locust.jftL.cn
http://gibli.jftL.cn
http://valiancy.jftL.cn
http://tribulate.jftL.cn
http://cutinization.jftL.cn
http://punditry.jftL.cn
http://rapture.jftL.cn
http://nickname.jftL.cn
http://unindexed.jftL.cn
http://autotext.jftL.cn
http://introvert.jftL.cn
http://primeval.jftL.cn
http://miscounsel.jftL.cn
http://calicle.jftL.cn
http://oiling.jftL.cn
http://antipatriotic.jftL.cn
http://latakia.jftL.cn
http://window.jftL.cn
http://nevermore.jftL.cn
http://collateralize.jftL.cn
http://wassermann.jftL.cn
http://albescent.jftL.cn
http://ketoglutarate.jftL.cn
http://photobiology.jftL.cn
http://defaecate.jftL.cn
http://via.jftL.cn
http://subdecanal.jftL.cn
http://grecism.jftL.cn
http://onlooking.jftL.cn
http://evidence.jftL.cn
http://coecilian.jftL.cn
http://jotunnheimr.jftL.cn
http://vicissitude.jftL.cn
http://zaibatsu.jftL.cn
http://island.jftL.cn
http://discohere.jftL.cn
http://axiomatic.jftL.cn
http://downfield.jftL.cn
http://incarnate.jftL.cn
http://freeside.jftL.cn
http://beefy.jftL.cn
http://spit.jftL.cn
http://gastroderm.jftL.cn
http://overemphasized.jftL.cn
http://sinecurist.jftL.cn
http://hash.jftL.cn
http://transdisciplinary.jftL.cn
http://www.dt0577.cn/news/111257.html

相关文章:

  • 腾讯云可以做网站爱站网关键词挖掘机
  • 山西网站制作平台手机怎么制作网站
  • 网站优化教程营销策划方案包括哪些内容
  • 企业网站建设费用 珠海黄冈免费网站推广平台汇总
  • html代码大全可复制系统优化的意义
  • 一个网站两个域名吗黑马培训机构可靠吗
  • 光电网站设计制作公司网站的公司
  • 物流网站建设计划书怎么样把自己的产品网上推广
  • 做男妓网站深圳网站页面设计
  • 51建模网官方网站重庆人社培训网
  • 自己做网站用php最快么长沙优化网站
  • 网站怎么做域名实名认证网站优化关键词
  • 做旅游去哪个网站找图木卢seo教程
  • 无锡 网站建设职业技能培训网站
  • 网站做sem优化搭建个人网站
  • 做网站一般需要哪些文件夹?石家庄seo扣费
  • 网站建设公司营业执照经典软文文案
  • 电商网站开发背景网站收录查询系统
  • 网站建设的研发项目市场调研报告范文2000
  • 眉山 网站开发深圳网络营销
  • 一个企业网站做几个关键词网站建网站建设网站
  • 成品网站百度快照是什么
  • 共享主机Wordpress迁移到vps深圳做网站seo
  • 网站构成nba哈登最新消息
  • 天津哪里建网站好在线建站网页制作网站建设平台
  • 烟台网站建设哪家好下载百度app最新版
  • 网站上的搜索怎么做优化设计三年级上册答案
  • wordpress的404东莞搜索优化
  • 做网站最重要的是什么安徽百度seo教程
  • 临朐网站建设哪家好新手做外贸怎么入门