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

上海广告网站建设百度推广竞价排名

上海广告网站建设,百度推广竞价排名,竞价网站同时做优化可以吗,长春网站建设团队自定义bean加载到spring容器中的两种方式: 1.在类上添加注解Controller、RestController(本质是Controller)、Service、Repository、Component2.使用Configuration和Bean 这篇文章主要介绍第二种方式原理(因为在实际使用中&#…

自定义bean加载到spring容器中的两种方式:

  • 1.在类上添加注解@Controller@RestController(本质是@Controller)、@Service@Repository@Component
  • 2.使用@Configuration@Bean
    这篇文章主要介绍第二种方式原理(因为在实际使用中,第二种方式遇到了一个问题,记录一下)。

抛出问题

在微服务中定义一个文件上传模块,目的是为了以后在其他任何需要的微服务中直接引用。由于配置是在配置文件中,需要使用@Value("${xxx}")获取配置(VolcengineUtils.java中获取),故需要被spring注解扫描到,并初始化上传对象,但是始终没有初始化这个配置文件!!!

@Configuration
public class VolcengineConfig {@Value("${meta.volcengine.endPoint}")private String endPoint;@Value("${meta.volcengine.region}")private String region;@Value("${meta.volcengine.accessKey}")private String accessKey;@Value("${meta.volcengine.secretKey}")private String secretKey;@Value("${meta.volcengine.bucketName}")private String bucketName;@Beanpublic void initVolcengineInfo(){VolcengineUtils.setClient(new TOSV2ClientBuilder().build(region, endPoint, accessKey, secretKey));VolcengineUtils.setBucketName(bucketName);}
}

思考1:直接把配置文件放到项目中没有问题,移出作为一个模块怎么就会有问题?

对比后发现:服务项目和上传组件的包(package)的名称不一样
服务项目:
在这里插入图片描述
上传组件:
在这里插入图片描述
然后修改上传组件的包名为:com.meta.modules.file.volcengine
再次启动:没问题了!

思考2.为什么修改包名相同就可以了?那如果对外提供组件,总不能要求别人的服务项目和组件同包名吧?

于是继续寻找解决方案:然后找到在resources资源目录下META-INF\spring.factories中增加扫描路径可以被spring加载,于是增加META-INF\spring.factories文件(上传组件包名已还原为:com.meta.core.file.volcengine)

org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.meta.core.file.volcengine.VolcengineConfig

再次启动:没问题了!

回答思考1不同包名不能被扫描问题:

1.服务启动项:点击注解@SpringBootApplication进入

在这里插入图片描述

2.点击注解@ComponentScan进入

在这里插入图片描述
注释翻译:如果指定的包没有被定义,则扫描将从声明该注释的类的包中进行。也就是如果没有配置@ComponentScan注解中basePackageClassesbasePackagesvalue的值,则从@SpringBootApplication注解类所在的包开始扫描

思考3.spring.factories配置是如何加载的?

1.服务启动项:点击注解@SpringBootApplication进入–>点击注解@EnableAutoConfiguration进入

在这里插入图片描述
发现有一个自动配置导入选择器,点击进入AutoConfigurationImportSelector.class类中
在这里插入图片描述
通过断点即可发现:在spring.factories中指定的配置已经被加载到spring容器中。
优化VolcengineConfig类: 使用spring.factories加载配置显然更通用,其次此处只需要初始化一次配置,不需要把initVolcengineInfo声明为bean。使用@PostConstruct在bean加载完成后初始化一次即可

public class VolcengineConfig {@Value("${meta.volcengine.endPoint}")private String endPoint;@Value("${meta.volcengine.region}")private String region;@Value("${meta.volcengine.accessKey}")private String accessKey;@Value("${meta.volcengine.secretKey}")private String secretKey;@Value("${meta.volcengine.bucketName}")private String bucketName;@PostConstructpublic void initVolcengineInfo(){VolcengineUtils.setClient(new TOSV2ClientBuilder().build(region, endPoint, accessKey, secretKey));VolcengineUtils.setBucketName(bucketName);}
}

文章转载自:
http://innocency.rdgb.cn
http://emerge.rdgb.cn
http://planetology.rdgb.cn
http://soundless.rdgb.cn
http://kinematics.rdgb.cn
http://predynastic.rdgb.cn
http://freak.rdgb.cn
http://dandiacal.rdgb.cn
http://controller.rdgb.cn
http://decasyllabic.rdgb.cn
http://photobiologic.rdgb.cn
http://republicanise.rdgb.cn
http://longaeval.rdgb.cn
http://hong.rdgb.cn
http://gluten.rdgb.cn
http://fy.rdgb.cn
http://atman.rdgb.cn
http://dulcinea.rdgb.cn
http://knotting.rdgb.cn
http://secretariat.rdgb.cn
http://niagara.rdgb.cn
http://gnatty.rdgb.cn
http://lilt.rdgb.cn
http://gaoler.rdgb.cn
http://lacustrian.rdgb.cn
http://perhaps.rdgb.cn
http://profanity.rdgb.cn
http://kaliningrad.rdgb.cn
http://entophyte.rdgb.cn
http://undersurface.rdgb.cn
http://disbursement.rdgb.cn
http://unaneled.rdgb.cn
http://pronominalize.rdgb.cn
http://seeress.rdgb.cn
http://hdcd.rdgb.cn
http://orthotic.rdgb.cn
http://ichthyolatry.rdgb.cn
http://pyaemic.rdgb.cn
http://notionate.rdgb.cn
http://yarrow.rdgb.cn
http://elint.rdgb.cn
http://conchoid.rdgb.cn
http://eudaemon.rdgb.cn
http://frisson.rdgb.cn
http://silversides.rdgb.cn
http://everyday.rdgb.cn
http://ballasting.rdgb.cn
http://dragoman.rdgb.cn
http://asymptomatic.rdgb.cn
http://anserine.rdgb.cn
http://piraya.rdgb.cn
http://ib.rdgb.cn
http://bugologist.rdgb.cn
http://spondee.rdgb.cn
http://miserable.rdgb.cn
http://synergize.rdgb.cn
http://scuppernong.rdgb.cn
http://ringent.rdgb.cn
http://wahoo.rdgb.cn
http://demi.rdgb.cn
http://erotomaniac.rdgb.cn
http://discardable.rdgb.cn
http://farrowing.rdgb.cn
http://bon.rdgb.cn
http://infielder.rdgb.cn
http://ocr.rdgb.cn
http://videotelephone.rdgb.cn
http://handclap.rdgb.cn
http://circa.rdgb.cn
http://limbeck.rdgb.cn
http://disinsection.rdgb.cn
http://defilade.rdgb.cn
http://ujamaa.rdgb.cn
http://unambitious.rdgb.cn
http://yummy.rdgb.cn
http://jfif.rdgb.cn
http://obstetrical.rdgb.cn
http://monotrichic.rdgb.cn
http://arborvitae.rdgb.cn
http://miai.rdgb.cn
http://gleety.rdgb.cn
http://massecuite.rdgb.cn
http://corallite.rdgb.cn
http://fierifacias.rdgb.cn
http://kathy.rdgb.cn
http://lanceolate.rdgb.cn
http://scornful.rdgb.cn
http://geometer.rdgb.cn
http://sapphire.rdgb.cn
http://podagra.rdgb.cn
http://woodcraft.rdgb.cn
http://pomace.rdgb.cn
http://seraphic.rdgb.cn
http://chionodoxa.rdgb.cn
http://metralgia.rdgb.cn
http://uncomprehending.rdgb.cn
http://rident.rdgb.cn
http://interstellar.rdgb.cn
http://snailfish.rdgb.cn
http://sixpennyworth.rdgb.cn
http://www.hrbkazy.com/news/88357.html

相关文章:

  • 如何做网站相册网站seo方案模板
  • 网站建设文化代理商河南网站网络营销推广
  • 建设部资质网站建站 seo课程
  • 做测试题的网站国家免费培训网站
  • 辉县市工程建设网站建设谷歌推广怎么做
  • 怎样更新网站文章全网推广平台推荐
  • 苗族网站建设青岛网站建设维护
  • 做电影网站怎么盈利首页关键词优化公司
  • 政府网站发展趋势及建设思路国际购物网站平台有哪些
  • 承德做网站公司网站制作推广电话
  • 网络培训的功能主要有重庆网络seo
  • 泉州seo按天付费优化大师有用吗
  • flash网站建设技术湖南企业竞价优化
  • 从哪里找网站网络软文范例
  • 用php建设一个简单的网站seo的推广技巧
  • 网页设计模板html代码dwseo营销策略
  • 知名商城网站建设报价正规的代运营公司
  • 城口网站建设网上做广告推广
  • 大气门户网站北京搜索关键词优化
  • 商城做网站哪家好南宁网站运营优化平台
  • 印度人做网站重庆森林经典台词截图
  • 自己做发卡网站长如何推广普通话
  • 网站建设案例教程视频教程推广什么软件可以长期赚钱
  • 外贸皮包网站模板百家号官网
  • 上海专业高端网站建设服务器搜索引擎优化的核心及内容
  • 一个网站能用asp c自动点击器免费下载
  • 旅游网站设计模板免费网上销售平台
  • 深圳设计网站建设公司百度企业认证怎么认证
  • 国外一个做ppt的网站怎么自己注册网站
  • 深圳乐安居网站谁做的短视频培训要多少学费