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

仙居做网站seo核心技术排名

仙居做网站,seo核心技术排名,北京企业网站建设公司,怎样做月嫂网站Spring注解使用中常见的概念性问题Configuration有什么用?Configuration和XML有什么区别?哪种好?Autowired 、 Inject、Resource 之间有什么区别?Value、PropertySource 和 Configuration?Spring如何处理带Configurati…

Spring注解使用中常见的概念性问题

  • @Configuration有什么用?
  • @Configuration和XML有什么区别?哪种好?
  • @Autowired 、 @Inject、@Resource 之间有什么区别?
  • @Value、@PropertySource 和 @Configuration?
  • Spring如何处理带@Configuration @Import的类?
  • @Profile有什么用?

@Configuration有什么用?

  1. @Configuration表明一个类中声明一个和多个@Bean标记的方法,并且这些方法被Spring容器管理用于生成Bean定义以及在运行时这些Bean的服务请求。
  2. 其实相当于原来的声明了多个bean的xml配置文件,而且被@Configuration也相当于一个组件。
  3. 加入@Configuration 注解,表明这就是一个配置类。有一个myBean()的方法并用@Bean 进行注释,返回一个MyBean()的实例,表明这个方法是需要被Spring进行管理的bean。@Bean 如果不指定名称的话,默认使用myBean名称,也就是小写的名称。
@Configuration
public class AppConfig {@Beanpublic MyBean myBean(){return new MyBean();}
}
  1. 可以通过使用 AnnotationConfigApplicationContext 来引导启动这个@Configuration 注解的类(在web项目中,也可以使用AnnotationContextWebApplicationContext或者其他变体来启动)
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(AppConfig.class);
ctx.refresh();
MyBean myBean = ctx.getBean(MyBean.class);
// use myBean ...
  1. 另外可以通过使用XML方式开启基于注解的启动,在/resources 目录下新建 application-context.xml 代码如下:
<?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"xmlns:util="http://www.springframework.org/schema/util"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsdhttp://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd"
><!-- 相当于基于注解的启动类 AnnotationConfigApplicationContext--><context:annotation-config /><bean class="com.linyf.demo.config.MyConfiguration"/>
</beans>

@Configuration和XML有什么区别?哪种好?

@Autowired 、 @Inject、@Resource 之间有什么区别?

  • @Inject: 这是jsr330 的规范,通过AutowiredAnnotationBeanPostProcessor 类实现的依赖注入。位于javax.inject包内,是Java自带的注解。
  • @Autowired: Spring提供的注解,通过AutowiredAnnotationBeanPostProcessor 类实现注入。位于org.springframework.beans.factory.annotation 包内。
  • @Resource: @Resource 是jsr250规范的实现,通过CommonAnnotationBeanPostProcessor 类实现注入。@Resource 一般会指定一个name属性

区别:
@Autowired和@Inject基本是一样的,因为两者都是使用AutowiredAnnotationBeanPostProcessor来处理依赖注入。但是@Resource是个例外,它使用的是CommonAnnotationBeanPostProcessor来处理依赖注入。当然,两者都是BeanPostProcessor。

@Value、@PropertySource 和 @Configuration?

  • @Configuration 可以和@Value 和@PropertySource 一起使用读取外部配置文件,

Spring如何处理带@Configuration @Import的类?

详情可以查看这篇文章:Spring/SpringBoot系列之SpringBoot 源码常用注解【九】

@Profile有什么用?

@Profile: 表示当一个或多个@Value 指定的配置文件处于可用状态时,组件符合注册条件,可以进行注册。

三种设置方式:

  1. 可以通过ConfigurableEnvironment.setActiveProfiles()以编程的方式激活

  2. 可以通过AbstractEnvironment.ACTIVE_PROFILES_PROPERTY_NAME (spring.profiles.active )属性设置为JVM属性

  3. 作为环境变量,或作为web.xml 应用程序的Servlet 上下文参数。也可以通过@ActiveProfiles 注解在集成测试中以声明方式激活配置文件。
    作用域:

  4. 作为类级别的注释在任意类或者直接与@Component 进行关联,包括@Configuration 类

  5. 作为原注解,可以自定义注解

  6. 作为方法的注解作用在任何方法
    注意:

如果一个配置类使用了Profile 标签或者@Profile
作用在任何类中都必须进行启用才会生效,如果@Profile({“p1”,“!p2”}) 标识两个属性,那么p1 是启用状态 而p2
是非启用状态的。
详见: https://blog.csdn.net/fei1234456/article/details/106905054/

http://www.hkea.cn/news/95637/

相关文章:

  • 做国珍新时代 网站陕西seo顾问服务
  • 建立网站怎么做关键字搜索引擎营销的作用
  • 广州手机网站建设宁波seo优化费用
  • 怎么设置网站服务器宁德市教育局官网
  • 查看网站源代码建站可以牛排seo系统
  • 政府网站建设的基本原则百度网盘电脑版
  • 张家港网站建设福州百度快速优化
  • 兼职做网站编辑百度搜索推广开户
  • 谁告诉你j2ee是做网站的宁波网站推广找哪家公司
  • 谷歌外贸建站多少钱搭建网站教程
  • 赚钱靠普的网站关键字搜索软件
  • 建设银行深分行圳招聘网站做游戏推广一个月能拿多少钱
  • 北京网站建设及推广招聘关键词排名代做
  • 对网站建设的意见建议网络营销推广的方法有哪些
  • 爬虫网站怎么做怎样才能在百度上面做广告宣传
  • 网站页码南昌做seo的公司有哪些
  • 网络设计方案包括哪些深圳百度推广seo公司
  • 亚马逊跨境电商开店站长工具seo综合查询5g
  • 网站怎么做百度快照logo百度快照优化推广
  • 山西网站建设排名seo技术培训山东
  • 日韩系成人影片成首选网站如何优化推广
  • 网站到期续费通知搜索风云排行榜
  • 网站公司说我们做的网站服务器不够用哪个杭州seo好
  • 类似淘宝网站建设费用杭州哪家seo公司好
  • 装修网站怎样做seo专员很难吗
  • 无锡网站外包如何接广告赚钱
  • 英文网站制作 官网淘宝标题优化网站
  • 电力建设网站网络推广网站的方法
  • 如何做网站窗口网站优化网络推广seo
  • 营销型网站建设效果网络营销策划推广方案