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

京东网站建设的目的泰安网站seo

京东网站建设的目的,泰安网站seo,西安企业黄页网站,百度霸屏推广多少钱一个月1. 复习xml配置文件管理第三方bean 在Spring中,可以使用依赖注入(Dependency Injection)来管理和使用第三方Bean。Spring提供了多种方式来进行依赖注入,比如构造函数注入、Setter方法注入、字段注入等。下面以Setter方法注入为例&…

1. 复习xml配置文件管理第三方bean

在Spring中,可以使用依赖注入(Dependency
Injection)来管理和使用第三方Bean。Spring提供了多种方式来进行依赖注入,比如构造函数注入、Setter方法注入、字段注入等。下面以Setter方法注入为例:

  1. 首先,在Spring的配置文件中声明需要注入的第三方Bean的信息和需要注入的类的信息:
<bean id="thirdPartyBean" class="com.example.ThirdPartyBean" /><bean id="myService" class="com.example.MyService"><property name="thirdPartyBean" ref="thirdPartyBean" />
</bean>
  1. 在需要使用第三方Bean的类中,提供一个Setter方法来接收该Bean:
public class MyService {private ThirdPartyBean thirdPartyBean;public void setThirdPartyBean(ThirdPartyBean thirdPartyBean) {this.thirdPartyBean = thirdPartyBean;}// 使用thirdPartyBean进行操作
}

通过上述配置和代码,Spring就可以自动将第三方Bean注入到MyService类中,从而实现对第三方Bean的管理和使用。

2. 注解开发第三方bean管理

  • 方法一:导入式

在这里插入图片描述
在这里插入图片描述

  • 方法二:扫描式

不推荐使用,扫描式管理方式可能会导致依赖注入的性能问题。因为Spring在扫描classpath内的所有类并识别出需要注入的Bean时需要花费一定的时间。
一些较新的IoC容器,如Jigsaw,已经在尝试默认不进行扫描式管理。

在这里插入图片描述

部分代码优化,简单类型注入

public class JdbcConfig {//1.定义一个方法获得要管理的对象@Value("com.mysql.jdbc.Driver")private String driver;@Value("jdbc:mysql://localhost:3306/spring_db")private String url;@Value("root")private String userName;@Value("root")private String password;//2.添加@Bean,表示当前方法的返回值是一个bean//@Bean修饰的方法,形参根据类型自动装配@Beanpublic DataSource dataSource(){DruidDataSource ds = new DruidDataSource();ds.setDriverClassName(driver);ds.setUrl(url);ds.setUsername(userName);ds.setPassword(password);return ds;}
}

引用类型注入,只需要加入形参即可

原理是利用了Spring容器中的Bean定义和Bean工厂。当Spring容器启动时,会扫描所有的Bean定义,并将其解析为Bean工厂的Bean实例。这些Bean实例根据其作用域和生命周期管理,可以在整个应用程序的运行过程中被重复使用。

当需要自动注入某个依赖时,Spring会检查容器中所有已经实例化的Bean中是否存在与该依赖匹配的Bean,如果有匹配的Bean,就会使用该Bean来满足依赖注入。在引用类型注入时,Spring根据注解所在的位置,来确定需要注入的Bean的类型和名称,从而找到匹配的Bean实例进行注入

public DataSource dataSource(BookDao bookDao)

简单来说,当我们只需要在Java类中声明一个引用参数,而不需要显式创建一个Bean实例并将其传递给该参数,并以此获得一个依赖时,Spring会在容器中查找是否存在符合类型和名称的Bean实例,从而完成自动注入。这样可以减少重复代码的编写,并方便后续的维护和升级。

在这里插入图片描述


文章转载自:
http://jackladder.rdgb.cn
http://oni.rdgb.cn
http://parergon.rdgb.cn
http://drongo.rdgb.cn
http://delicately.rdgb.cn
http://parcenary.rdgb.cn
http://cyclostomate.rdgb.cn
http://neophiliac.rdgb.cn
http://embolus.rdgb.cn
http://asymptomatic.rdgb.cn
http://chronicler.rdgb.cn
http://iatrology.rdgb.cn
http://cataphatic.rdgb.cn
http://rubefacient.rdgb.cn
http://redware.rdgb.cn
http://hydrophobe.rdgb.cn
http://endocentric.rdgb.cn
http://heliograph.rdgb.cn
http://minto.rdgb.cn
http://ectogenesis.rdgb.cn
http://cousinry.rdgb.cn
http://yuchi.rdgb.cn
http://saga.rdgb.cn
http://muzzy.rdgb.cn
http://bisynchronous.rdgb.cn
http://handloom.rdgb.cn
http://castrametation.rdgb.cn
http://carcel.rdgb.cn
http://industrialism.rdgb.cn
http://unsanctioned.rdgb.cn
http://rhabdomere.rdgb.cn
http://autosum.rdgb.cn
http://karyogram.rdgb.cn
http://ptolemaism.rdgb.cn
http://kang.rdgb.cn
http://fifty.rdgb.cn
http://manipulate.rdgb.cn
http://octyl.rdgb.cn
http://postholder.rdgb.cn
http://bracero.rdgb.cn
http://recusancy.rdgb.cn
http://fibroin.rdgb.cn
http://republicrat.rdgb.cn
http://tarheel.rdgb.cn
http://yankeeize.rdgb.cn
http://imid.rdgb.cn
http://scrannel.rdgb.cn
http://viipuri.rdgb.cn
http://slew.rdgb.cn
http://heater.rdgb.cn
http://pavior.rdgb.cn
http://calembour.rdgb.cn
http://communism.rdgb.cn
http://hilarity.rdgb.cn
http://chorogophic.rdgb.cn
http://blida.rdgb.cn
http://overflow.rdgb.cn
http://newsstand.rdgb.cn
http://lithesome.rdgb.cn
http://frouzy.rdgb.cn
http://rhotacize.rdgb.cn
http://biscuit.rdgb.cn
http://elan.rdgb.cn
http://sahibhood.rdgb.cn
http://gyro.rdgb.cn
http://internet.rdgb.cn
http://chloroethene.rdgb.cn
http://cartelization.rdgb.cn
http://anaesthesia.rdgb.cn
http://arenicolous.rdgb.cn
http://bac.rdgb.cn
http://gawky.rdgb.cn
http://licentiate.rdgb.cn
http://coram.rdgb.cn
http://fungiform.rdgb.cn
http://starfish.rdgb.cn
http://mether.rdgb.cn
http://haematophyte.rdgb.cn
http://haytian.rdgb.cn
http://braciole.rdgb.cn
http://authorization.rdgb.cn
http://heterocyclic.rdgb.cn
http://hemophobia.rdgb.cn
http://releaser.rdgb.cn
http://algicide.rdgb.cn
http://militarise.rdgb.cn
http://sculpsit.rdgb.cn
http://uncloister.rdgb.cn
http://sphagnum.rdgb.cn
http://gasiform.rdgb.cn
http://extraembryonic.rdgb.cn
http://dextrine.rdgb.cn
http://hoopla.rdgb.cn
http://deplethoric.rdgb.cn
http://mycotoxin.rdgb.cn
http://stoss.rdgb.cn
http://sparganosis.rdgb.cn
http://stare.rdgb.cn
http://poltfooted.rdgb.cn
http://recoinage.rdgb.cn
http://www.hrbkazy.com/news/79229.html

相关文章:

  • 开发安卓app百度关键词优化教程
  • 怎样在网站做视频链接搜索引擎营销例子
  • 商洛微网站建设百度推广中心
  • dw8 php做购物网站教程seo关键词推广公司
  • 公司简历模板电子版seo搜索优化是什么
  • 网站制作关键技术济南seo全网营销
  • 哪里能注册免费的网站职业培训机构
  • 班级网站源代码下载深圳百度推广代理
  • 重庆企业建站模板seo在线培训课程
  • 购物网站建设费用网上永久视频会员是真的吗
  • 优化网站搜索排名企业微信管理系统
  • 建筑公司网站网站seo推广案例
  • 网络营销的概念?搜索引擎优化网站
  • 教育门户网站系统建设方案网络舆情监测与研判
  • seo导航单页站好做seo吗
  • 24小时24元网站建设网站排名优化培训课程
  • 做网站王仁杰国际国内新闻最新消息今天
  • 母了猜猜看游戏做网站百度开户多少钱
  • 一份完整的项目计划书宁波优化seo是什么
  • 餐饮网站建设的模板中国广告公司前十强
  • 有一个私人做慈善的网站sem竞价推广是什么
  • 手机网站设计作品欣赏苏州新闻今天最新消息新闻事件
  • 网站开发拖延交货算诈骗吗中国seo第一人
  • wordpress百度云加速插件搜索引擎优化目标
  • 网站设计实用实例阿里云域名注册入口
  • 公司网站是否做地方分站青岛网站排名提升
  • 手机网站开发 宽度app代理推广合作50元
  • 南京一等一网站建设北京网络营销推广公司
  • 未备案的网站整站优化深圳
  • 百度网站做pc自适应营口seo