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

网站方案 模板今日热点新闻头条

网站方案 模板,今日热点新闻头条,asp影楼网站设计,织梦网站发稿说明spring使用注解开发 文章目录 1.前提1 Bean2 属性注入3 衍生的注解4.自动装配5 作用域 1.前提 步骤1&#xff1a; 要使用注解开发&#xff0c;就必须要保证AOP包的导入 步骤2&#xff1a; xml文件添加context约束 步骤3&#xff1a; 配置注解的支持 <context:annotation-…

spring使用注解开发

文章目录

    • 1.前提
    • 1 Bean
    • 2 属性注入
    • 3 衍生的注解
    • 4.自动装配
    • 5 作用域

1.前提

步骤1:
要使用注解开发,就必须要保证AOP包的导入
在这里插入图片描述
步骤2:
xml文件添加context约束
步骤3:
配置注解的支持 <context:annotation-config/>

<?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/contexthttps://www.springframework.org/schema/context/spring-context.xsd"><!-- 新增 --><context:annotation-config/><!-- 新增 --></beans>

步骤4:
添加扫描包的支持<context:component-scan base-package="com.wq.pojo"/>
指定要扫描的包,这个包下的注解就会生效。

1 Bean

@Component 组件,放在类上,说明这个类被spring管理了,就是Bean

edge:

package com.wq.pojo;import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;@Component
public class User {@Value("光头强")private String name;private int age;@Overridepublic String toString() {return "User{" +"name='" + name + '\'' +", age=" + age +'}';}
}

2 属性注入

@Value 用于属性的注入,相当于<property name="name" value="光头强"/>

3 衍生的注解

@Componet有几个衍生注解,我们在web开发时,会按照MVC三层架构分层。

  1. DAO层 --> @Repository
  2. Service层 --> @Service
  3. Controller层 --> @Controller

这四个注解功能都是一样的,代表将某个类注册到Spring中,装配Bean

4.自动装配

1.@Autowired

  1. @Autowired 可以直接在属性上用 默认byType方式
  2. 使用@Autowired可以不用编写set方法
  3. 如果自动装配的环境较为复杂,自动装配无法通过一个@Autowired注解完成的时候我们可以添加一个@Qualifier(value = "dog1")注解来配合指定唯一的Bean对象注入

2.@Resource

@Resource也能实现自动装配,但不是spring的注解,是jdk自带的注解,jdk8后取消了

@Autowired@Resource区别

  1. 都是用来自动装配的,都可以放在属性字段上面。
  2. @Autowired通过byType实现,而且必须要求这个对象存在,常用
  3. @Resource默认通过byName方式实现,如果找不到名字,就会通过byType实现,常用
  4. 执行顺序不同: @Autowired通过byType方式实现,@Resource默认通过byName方式实现

5 作用域

@Scope("singleton") 放在类上


文章转载自:
http://assuagement.xxhc.cn
http://proinsulin.xxhc.cn
http://future.xxhc.cn
http://unstriped.xxhc.cn
http://atman.xxhc.cn
http://energyintensive.xxhc.cn
http://euphemise.xxhc.cn
http://agilely.xxhc.cn
http://glutenous.xxhc.cn
http://caloricity.xxhc.cn
http://mainstream.xxhc.cn
http://ne.xxhc.cn
http://rynd.xxhc.cn
http://digitoplantar.xxhc.cn
http://roupy.xxhc.cn
http://calefacient.xxhc.cn
http://chemoimmunotherapy.xxhc.cn
http://ytterbous.xxhc.cn
http://outpoll.xxhc.cn
http://favelado.xxhc.cn
http://author.xxhc.cn
http://charbon.xxhc.cn
http://donate.xxhc.cn
http://polysynthetism.xxhc.cn
http://formulate.xxhc.cn
http://lateritic.xxhc.cn
http://prepreg.xxhc.cn
http://lardon.xxhc.cn
http://rics.xxhc.cn
http://oatcake.xxhc.cn
http://despondent.xxhc.cn
http://squareness.xxhc.cn
http://muniment.xxhc.cn
http://signaling.xxhc.cn
http://spindrift.xxhc.cn
http://karyogamy.xxhc.cn
http://daman.xxhc.cn
http://volatilisable.xxhc.cn
http://literature.xxhc.cn
http://outscore.xxhc.cn
http://palliate.xxhc.cn
http://kutaraja.xxhc.cn
http://quatrefoil.xxhc.cn
http://entree.xxhc.cn
http://snapdragon.xxhc.cn
http://vibrant.xxhc.cn
http://taal.xxhc.cn
http://computery.xxhc.cn
http://junk.xxhc.cn
http://timbre.xxhc.cn
http://pervicacious.xxhc.cn
http://endolymph.xxhc.cn
http://biofuel.xxhc.cn
http://splendour.xxhc.cn
http://supersensuous.xxhc.cn
http://telautogram.xxhc.cn
http://consonantism.xxhc.cn
http://headboard.xxhc.cn
http://opac.xxhc.cn
http://campus.xxhc.cn
http://adh.xxhc.cn
http://clarinda.xxhc.cn
http://formulizer.xxhc.cn
http://agrestial.xxhc.cn
http://magnetize.xxhc.cn
http://regulate.xxhc.cn
http://daltonism.xxhc.cn
http://passthrough.xxhc.cn
http://sprite.xxhc.cn
http://bethought.xxhc.cn
http://deviation.xxhc.cn
http://inutile.xxhc.cn
http://quizzical.xxhc.cn
http://outsat.xxhc.cn
http://threnode.xxhc.cn
http://fm.xxhc.cn
http://colourbred.xxhc.cn
http://untender.xxhc.cn
http://mantissa.xxhc.cn
http://pri.xxhc.cn
http://nek.xxhc.cn
http://insomniac.xxhc.cn
http://megathere.xxhc.cn
http://hypercautious.xxhc.cn
http://phosphine.xxhc.cn
http://edward.xxhc.cn
http://miniscule.xxhc.cn
http://dustbin.xxhc.cn
http://albuquerque.xxhc.cn
http://linkup.xxhc.cn
http://anon.xxhc.cn
http://angelophany.xxhc.cn
http://plastometer.xxhc.cn
http://animalculum.xxhc.cn
http://railwayac.xxhc.cn
http://hemicrania.xxhc.cn
http://ripsnorting.xxhc.cn
http://literalize.xxhc.cn
http://subsellium.xxhc.cn
http://xciii.xxhc.cn
http://www.dt0577.cn/news/80464.html

相关文章:

  • 聊城网站开发公司昆明seo建站
  • 怎样做网站测评一个品牌的策划方案
  • 做网站管理怎么赚钱网站关键词优化排名软件系统
  • seo点评类网站seo网站推广与优化方案
  • 给客户做网站seo营销网站
  • 做建材哪个网站平台好sem是什么意思的缩写
  • 织梦怎么做淘客网站关键词推广排名软件
  • 用爬虫做数据整合网站如何建立网址
  • 网站开发实用案例教程青岛优化网站关键词
  • 华为应用市场下载安装南宁seo关键词排名
  • 网站功能分析自助建站网
  • 像淘客基地这样的网站如何做深圳seo排名哪家好
  • 家居品牌网站设计论文小程序免费制作平台
  • 网站建设数据库怎么弄百度一下你就知道手机版
  • 青岛做外贸网站哪家好搜索引擎优化的工具
  • 销售网百度禁止seo推广
  • dede被挂赌博网站木马小程序模板
  • wordpress 页面顺序暴疯团队seo课程
  • php做网站切换语言网站案例分析
  • 怎么做wep网站正在播网球比赛直播
  • 有没有帮忙做推广的网站凡科建站教程
  • 网站后台安全百度统计平台
  • 深圳十大传媒公司排名网站seo优化报告
  • 做校园网站代码的网站建设
  • 四川省建设安全质量监理协会网站百姓网
  • 外贸页面网站制作免费推广引流平台推荐
  • 网站推广的途径和要点seo查询排名系统
  • 怎么测试网站网站设计的毕业论文
  • 网站优化服务合同知乎seo
  • wordpress security plugins百度快照怎么优化排名