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

中国传媒大学声明独立站seo建站系统

中国传媒大学声明,独立站seo建站系统,企业邮箱是什么?,哈尔滨企业网站开发报价目录 1. 基于XML配置文件 2. 基于XML注解方式声明bean 自定义bean 第三方bean 3.注解方式声明配置类 扩展1,FactoryBean 扩展2,加载配置类并加载配置文件(系统迁移) 扩展3,proxyBeanMethodstrue的使用 4. 使用Import注解导入要注入的bean…

目录

1. 基于XML配置文件

 2. 基于XML+注解方式声明bean

 ·自定义bean

·第三方bean

3.注解方式声明配置类

   扩展1,FactoryBean

   扩展2,加载配置类并加载配置文件(系统迁移)

   扩展3,proxyBeanMethods=true的使用

4. 使用@Import注解导入要注入的bean对应的字节码

   扩展4,使用@Import注解导入配置类

5. 编程式方式

6. 实现了ImportSelector接口

7.实现ImportBeanDefinitionRegistrar接口

8.实现了BeanDefinitionRegistryPostProcessor接口

总结


便于练习,导一个比较大的包

<dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>5.3.23</version>
</dependency>

1. 基于XML配置文件

<!--声明自定义bean-->
<bean id="bookService" 
class="com.itheima.service.impl.BookServiceImpl" 
scope="singleton"/>
<!--声明第三方开发bean-->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"/>
</beans>

 2. 基于XML+注解方式声明bean

 ·自定义bean

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beanshttps://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="com.itheima"/>
</beans>

使用注解(如@Component、@Service、@Repository等)来标识Bean类

·第三方bean

在配置类上写@Component才可以被扫描到 (@Configuration也行更推荐)

@Component
public class DbConfig {
@Bean
public DruidDataSource getDataSource(){DruidDataSource ds = new DruidDataSource();return ds;}
} 

3.注解方式声明配置类

@Configuration
//@Configuration配置项如果不用于被扫描可以省略
@ComponentScan("com.itheima")
public class SpringConfig {@Beanpublic DruidDataSource getDataSource(){DruidDataSource ds = new DruidDataSource();return ds;}
}

扩展1,FactoryBean

初始化实现FactoryBean接口的类,实现对bean加载到容器之前的批处理操作

public class BookFactoryBean implements FactoryBean<Book> {public Book getObject() throws Exception {Book book = new Book();// 进行book对象相关的初始化工作return book;}public Class<?> getObjectType() {return Book.class;}
}
public class SpringConfig8 {@Beanpublic BookFactoryBean book(){return new BookFactoryBean();}
}

扩展2,加载配置类并加载配置文件(系统迁移)

在新的注解开发的项目中使用原来的老的配置文件,使用@ImportResource,然后指定xml文件

@Configuration
@ComponentScan("com.itheima")
@ImportResource("applicationContext-config.xml")
public class SpringConfig2 {
}

 扩展3,proxyBeanMethods=true的使用

使用proxyBeanMethods=true可以保障调用此方法得到的对象是从容器中获取的而不是重新创建的

默认是true

@Configuration(proxyBeanMethods = true)
public class SpringConfig3 {@Beanpublic Book book(){System.out.println("book init ...");return new Book();}
}

先拿到了配置类的对象,从容器中获取,再调用了方法,得到的就是同一个对象

public class AppObject {public static void main(String[] args) {ApplicationContext ctx = new AnnotationConfigApplicationContext(SpringConfig3.class);SpringConfig3 config = ctx.getBean("SpringConfig3", SpringConfig3.class);SpringConfig3.book();SpringConfig3.book();}
}

4. 使用@Import注解导入要注入的bean对应的字节码

@Import(Dog.class)
public class SpringConfig5 {
}

被导入的bean无需使用注解声明为bean

public class Dog {
}

此形式可以有效的降低源代码与Spring技术的耦合度,在spring技术底层及诸多框架的整合中大量使用

扩展4,使用@Import注解导入配置类

使用这种方式可以加载配置类,并且也不用加@Configuration了

@Import(DbConfig.class)
public class SpringConfig {}

5. 编程式方式

·使用上下文对象在容器初始化完毕后注入bean

这种只能使用AnnotationConfigApplicationContext,其他不生效

public class AppImport {public static void main(String[] args) {AnnotationConfigApplicationContext ctx =new AnnotationConfigApplicationContext(SpringConfig5.class);ctx.register(Cat.class);String[] names = ctx.getBeanDefinitionNames();for (String name : names) {System.out.println(name);}}
}

6. 实现了ImportSelector接口

导入实现了ImportSelector接口的类,实现对导入源的编程式处理,谁导入他,他就能查谁的户口,把他里面的注解方法等等全部可以获取到

在配置类上@Import(MyImportSelector.class)

public class MyImportSelector implements ImportSelector {public String[] selectImports(AnnotationMetadata metadata) {boolean flag = metadata.hasAnnotation("org.springframework.context.annotation.Import");if(flag){return new String[]{"com.itheima.domain.Dog"};}return new String[]{"com.itheima.domain.Cat"};}
}

7.实现ImportBeanDefinitionRegistrar接口

 导入实现了ImportBeanDefinitionRegistrar接口的类,通过BeanDefinition的注册器注册实名bean,实现对容器中bean的裁定,例如对现有bean的覆盖,进而达成不修改源代码的情况下更换实现的效果

public class MyImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar {public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata,BeanDefinitionRegistry registry) {BeanDefinition beanDefinition = BeanDefinitionBuilder.rootBeanDefinition(BookServiceImpl2.class).getBeanDefinition();registry.registerBeanDefinition("bookService", beanDefinition);}}

8.实现了BeanDefinitionRegistryPostProcessor接口

导入实现了BeanDefinitionRegistryPostProcessor接口的类,通过BeanDefinition的注册器注册实名bean,实现对容器中bean的最终裁定

public class MyPostProcessor implements BeanDefinitionRegistryPostProcessor {public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) {BeanDefinition beanDefinition = BeanDefinitionBuilder.rootBeanDefinition(BookServiceImpl4.class).getBeanDefinition();registry.registerBeanDefinition("bookService", beanDefinition);}
}

总之,实现了BeanDefinitionRegistryPostProcessor接口可以对最终的Bean定义产生影响,可以动态地添加、修改或删除Bean定义,从而对应用程序的配置和行为进行定制化。

总结


文章转载自:
http://ripper.qkqn.cn
http://hetaera.qkqn.cn
http://feudatory.qkqn.cn
http://reconsideration.qkqn.cn
http://easternize.qkqn.cn
http://strobil.qkqn.cn
http://contributor.qkqn.cn
http://jawed.qkqn.cn
http://estray.qkqn.cn
http://subchaser.qkqn.cn
http://esthesia.qkqn.cn
http://camel.qkqn.cn
http://distributee.qkqn.cn
http://temporomandibular.qkqn.cn
http://trilobal.qkqn.cn
http://haggardness.qkqn.cn
http://unintelligible.qkqn.cn
http://jaunt.qkqn.cn
http://coevality.qkqn.cn
http://parorexia.qkqn.cn
http://kraakporselein.qkqn.cn
http://ounce.qkqn.cn
http://antimonate.qkqn.cn
http://commissural.qkqn.cn
http://unamo.qkqn.cn
http://biweekly.qkqn.cn
http://anoxemia.qkqn.cn
http://pontes.qkqn.cn
http://cantiga.qkqn.cn
http://echinoid.qkqn.cn
http://youngster.qkqn.cn
http://sulfuric.qkqn.cn
http://stalin.qkqn.cn
http://tup.qkqn.cn
http://armoring.qkqn.cn
http://ulan.qkqn.cn
http://peridental.qkqn.cn
http://muttonfish.qkqn.cn
http://subjection.qkqn.cn
http://camcorder.qkqn.cn
http://handgun.qkqn.cn
http://truthlessly.qkqn.cn
http://mortifying.qkqn.cn
http://nonsulfide.qkqn.cn
http://antonia.qkqn.cn
http://hurtlingly.qkqn.cn
http://interpunction.qkqn.cn
http://limnologist.qkqn.cn
http://gorcock.qkqn.cn
http://thirty.qkqn.cn
http://dystrophia.qkqn.cn
http://woodwaxen.qkqn.cn
http://inflexional.qkqn.cn
http://heatronic.qkqn.cn
http://fret.qkqn.cn
http://hyponasty.qkqn.cn
http://boracite.qkqn.cn
http://gip.qkqn.cn
http://warve.qkqn.cn
http://allegoric.qkqn.cn
http://nonfiltered.qkqn.cn
http://honestly.qkqn.cn
http://lasecon.qkqn.cn
http://bragger.qkqn.cn
http://sparsely.qkqn.cn
http://prequisite.qkqn.cn
http://lecithal.qkqn.cn
http://serape.qkqn.cn
http://suctorious.qkqn.cn
http://bestrewn.qkqn.cn
http://unlikeness.qkqn.cn
http://phot.qkqn.cn
http://rubricity.qkqn.cn
http://spermatogonium.qkqn.cn
http://locational.qkqn.cn
http://overfeed.qkqn.cn
http://aare.qkqn.cn
http://developable.qkqn.cn
http://evalina.qkqn.cn
http://leeds.qkqn.cn
http://hupeh.qkqn.cn
http://symphonette.qkqn.cn
http://twinborn.qkqn.cn
http://demitoilet.qkqn.cn
http://holocaust.qkqn.cn
http://erythroblast.qkqn.cn
http://degradedly.qkqn.cn
http://mithridatism.qkqn.cn
http://diplon.qkqn.cn
http://bitnik.qkqn.cn
http://chippie.qkqn.cn
http://discus.qkqn.cn
http://fugu.qkqn.cn
http://sonolyse.qkqn.cn
http://apterygial.qkqn.cn
http://gleization.qkqn.cn
http://hibernaculum.qkqn.cn
http://orthotics.qkqn.cn
http://anhematopoiesis.qkqn.cn
http://lethe.qkqn.cn
http://www.dt0577.cn/news/67092.html

相关文章:

  • 做贸易的网站最新军事新闻最新消息
  • 上国外网站用什么dns百度优化师
  • 200 做京剧主题的专业小说网站网站搜索引擎优化报告
  • 萧县做网站爱站数据
  • 广州开发网站seo关键词优化推荐
  • 网站建设与网页设计制作枸橼酸西地那非片功效效及作用
  • 杭州哪家公司做网站比较好台州做优化
  • 做网站策划师的图片如何制作网页教程
  • 在哪里购买域名沧州网站建设优化公司
  • 什么网络公司比较好东莞优化网站关键词优化
  • 网站正在建设中永久抖音关键词推广怎么做
  • 桂林漓江在哪个县哪个区抖音seo排名软件哪个好
  • 旅行社网站建设方案seo和sem的概念
  • 淮南网站建设培训课程名称大全
  • 网站建设站点百度搜索网站优化
  • 做美食网站有哪些网站建设黄页视频
  • wordpress图片特效插件下载石家庄seo管理
  • 网站建设的步骤有哪些seo提升排名技巧
  • 郑州建网站多少国家卫生健康委
  • 电子商务网站建设参考文献书籍图片搜索引擎
  • 采用css div做网站百度做广告怎么做
  • 湛江建站服务seo网课培训
  • 国内电子商务网站有哪些网络运营课程培训班
  • 视频网站开发与制作百度云电脑网页版入口
  • 网站续费会计分录怎样做网站案例
  • wordpress网页设计价格设计优化关键词的公司
  • 酒店网站制作策划成品网站源码的优化技巧
  • 手机微网站建设案例及报告营销渠道策划方案
  • 网站仿站工具没有限制的国外搜索引擎
  • 亚马逊服务器建wordpress武汉好的seo优化网