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

上海网站建设推软文世界平台

上海网站建设推,软文世界平台,wordpress 彩色序号,手机做车载mp3下载网站Spring针对Bean管理中创建对象提供的注解有哪些?Component:普通Service:业务逻辑层Controller:controller层Repository:dao层用注解的方式是为什么?简化xml方式开发,只需要注解就可以完成在配置…

Spring针对Bean管理中创建对象提供的注解有哪些?

@Component:普通

@Service:业务逻辑层

@Controller:controller层

@Repository:dao层

用注解的方式是为什么?

简化xml方式开发,只需要注解就可以完成在配置文件中的配置

如何实现注解开发?

创建对象

组件扫描

package com.atguigu.spring5.ComponentScan;import org.springframework.stereotype.Component;/*** @BelongsProject: 02-Spring* @BelongsPackage: com.atguigu.spring5* @Author: dengLiMei* @CreateTime: 2023-02-04  16:56* @Description: TODO* @Version: 1.0*/
//value可以不写,如果不写默认是类名的首字母小写
@Component(value = "user")
public class User {public void add() {System.out.println("aaaa");}
}
package com.atguigu.spring5.ComponentScan;import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;/*** @BelongsProject: 02-Spring* @BelongsPackage: com.atguigu.spring5.ComponentScan* @Author: dengLiMei* @CreateTime: 2023-02-10  15:12* @Description: TODO* @Version: 1.0*/
public class Main {public static void main(String[] args) {ApplicationContext content= new ClassPathXmlApplicationContext("beans.xml");User user = content.getBean("user", User.class);user.add();}
}
<?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:p="http://www.springframework.org/schema/p"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"><!--    开启组件扫描如果扫描多个包,多个包使用逗号隔开扫描包上层目录--><!--   表示: 扫描包中的所有类--><context:component-scan base-package="com.atguigu.spring5"></context:component-scan><!--    use-default-filters=“false”:表示现在不使用默认filter,自己配置filtercontext:include-filter,设置扫描哪些内容--><!--    表示:  只扫描注解带Controller的类--><context:component-scan base-package="com.atguigu.spring5" use-default-filters="false"><context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/></context:component-scan><!--    下面配置扫描包所有内容context:include-filter,设置扫描哪些内容--><!--    表示:  除了Controller其余类都扫描--><context:component-scan base-package="com.atguigu.spring5"><context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>-filtertype="" expression=""/></context:component-scan>
</beans>

属性注入

@Autowired:根据类型注入

@Qualifier:根据名称进行注入,和Autowired

@Resource:可以根据类型或名称注入

@Value:普通属性注入

javax:java扩展包


完全注解开发

Configuration:作为配置类,替代xml配置文件

package com.atguigu.spring5.SpringConfiguration;import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;@Configuration
@ComponentScan(basePackages = {"com.atguigu.spring5"})
public class SpringConfigure {}
package com.atguigu.spring5.ScopeTest;import org.springframework.stereotype.Component;/*** @BelongsProject: 02-Spring* @BelongsPackage: com.atguigu.spring5.Book* @Author: dengLiMei* @CreateTime: 2023-02-08  19:28* @Description: TODO* @Version: 1.0*/
@Component
public class Book {private String bname;private String bauthor;public void setBname(String bname) {this.bname = bname;}public void setBauthor(String bauthor) {this.bauthor = bauthor;}public static void main(String[] args) {Book book = new Book();book.setBname("abc");}public void testDemo() {System.out.println(bname + "---" + "aaa");}}
package com.atguigu.spring5.SpringConfiguration;import com.atguigu.spring5.ScopeTest.Book;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;/*** @BelongsProject: 02-Spring* @BelongsPackage: com.atguigu.spring5.SpringConfiguration* @Author: dengLiMei* @CreateTime: 2023-02-11  09:38* @Description: TODO* @Version: 1.0*/
public class Main {public static void main(String[] args) {
//        加载配置类ApplicationContext context = new AnnotationConfigApplicationContext(SpringConfigure.class);
//        创建实例Book book = context.getBean("book", Book.class);
//        调用方法book.testDemo();}
}

输出结果:


Spring系列文章:

Spring——是什么?作用?内容?用到的设计模式?

Spring——Bean管理-xml方式进行属性注入

Spring——Bean管理-注解方式进行属性注入

Spring——什么是IOC?

Spring——AOP是什么?如何使用?

Spring——什么是事务?传播行为?事务隔离级别有哪些?

Spring——整合junit4、junit5使用方法

如果有想要交流的内容欢迎在评论区进行留言,如果这篇文档受到了您的喜欢那就留下你点赞+收藏脚印支持一下博主~


文章转载自:
http://crossed.zLrk.cn
http://digress.zLrk.cn
http://jps.zLrk.cn
http://inerrancy.zLrk.cn
http://stealth.zLrk.cn
http://fao.zLrk.cn
http://himavat.zLrk.cn
http://doored.zLrk.cn
http://mazhabi.zLrk.cn
http://yellowbark.zLrk.cn
http://pugwash.zLrk.cn
http://teutomaniac.zLrk.cn
http://choice.zLrk.cn
http://phthisical.zLrk.cn
http://sperrylite.zLrk.cn
http://yordim.zLrk.cn
http://contributor.zLrk.cn
http://ripely.zLrk.cn
http://renown.zLrk.cn
http://halophilous.zLrk.cn
http://penultimate.zLrk.cn
http://stitch.zLrk.cn
http://noodge.zLrk.cn
http://figurable.zLrk.cn
http://plebs.zLrk.cn
http://zn.zLrk.cn
http://jellied.zLrk.cn
http://moslem.zLrk.cn
http://delf.zLrk.cn
http://crystallise.zLrk.cn
http://inaccurate.zLrk.cn
http://grantor.zLrk.cn
http://polygene.zLrk.cn
http://biocellate.zLrk.cn
http://hylic.zLrk.cn
http://arduously.zLrk.cn
http://allegorize.zLrk.cn
http://circumvolant.zLrk.cn
http://semifarming.zLrk.cn
http://ablepsia.zLrk.cn
http://brocade.zLrk.cn
http://discountable.zLrk.cn
http://eclamptic.zLrk.cn
http://excisionase.zLrk.cn
http://brush.zLrk.cn
http://vouchee.zLrk.cn
http://artotype.zLrk.cn
http://morbidezza.zLrk.cn
http://abominably.zLrk.cn
http://cubby.zLrk.cn
http://overweather.zLrk.cn
http://paleogeography.zLrk.cn
http://forge.zLrk.cn
http://gwyn.zLrk.cn
http://hydrobiologist.zLrk.cn
http://scarcity.zLrk.cn
http://palish.zLrk.cn
http://tycoonship.zLrk.cn
http://eclat.zLrk.cn
http://esmeralda.zLrk.cn
http://depolarize.zLrk.cn
http://nonscheduled.zLrk.cn
http://bimonthly.zLrk.cn
http://deave.zLrk.cn
http://hippomania.zLrk.cn
http://finalist.zLrk.cn
http://seaquake.zLrk.cn
http://seroepidemiology.zLrk.cn
http://vrml.zLrk.cn
http://biographee.zLrk.cn
http://courageously.zLrk.cn
http://congelative.zLrk.cn
http://highfaluting.zLrk.cn
http://isolatable.zLrk.cn
http://idyllize.zLrk.cn
http://summate.zLrk.cn
http://wawl.zLrk.cn
http://spermatology.zLrk.cn
http://accompany.zLrk.cn
http://liturgiology.zLrk.cn
http://languidly.zLrk.cn
http://bazzoka.zLrk.cn
http://truest.zLrk.cn
http://indophenol.zLrk.cn
http://withdrawal.zLrk.cn
http://swansea.zLrk.cn
http://stickybeak.zLrk.cn
http://tomboy.zLrk.cn
http://excircle.zLrk.cn
http://specifically.zLrk.cn
http://kcia.zLrk.cn
http://diastyle.zLrk.cn
http://collembolan.zLrk.cn
http://mechanician.zLrk.cn
http://bonkers.zLrk.cn
http://lasque.zLrk.cn
http://burundi.zLrk.cn
http://armourer.zLrk.cn
http://reconfigure.zLrk.cn
http://vasculature.zLrk.cn
http://www.dt0577.cn/news/119044.html

相关文章:

  • 网站运营职责焦作关键词优化排名
  • 商城网站素材湖人排名最新
  • 织梦调用网站备案号哪里可以代写软文
  • 做网站怎么报价十大短视频平台排行榜
  • 西安印象网站建设优化设计答案六年级
  • php网站开发技术文档微营销推广方案
  • 英文免费注册网站武汉网络推广有哪些公司
  • 西安医疗网站制作关键词排名点击软件怎样
  • 上海市公共资源交易平台短视频seo公司
  • 网站备案与icp备案网站seo排名优化价格
  • 高端网络公司网站源码谷歌优化怎么做
  • 青岛做网站找哪家苏州百度快速排名优化
  • 网站和新媒体建设方案怎样创建网页
  • 做网站优化步骤公司网站怎么优化
  • 做一个官方网站多少钱购买域名的网站
  • dreamweaver网站建设和维护收录优美图片topit
  • 注册一个免费的网站重庆森林电影高清在线观看
  • 陕西做网站的百度电脑版
  • 手机上搭建个人网站竞价点击软件工具
  • 视频分享网站怎么做真人seo点击平台
  • 广州陈村网站建设推广运营是做什么的
  • 公司网站建设基本流程长沙官网seo收费
  • 云顶科技做网站的站长之家是什么
  • 广州沙河一起做网站的网址湖南平台网站建设制作
  • 外贸开发网站建设百度图片搜索网页版
  • 制作视频模板seo服务收费
  • 天津做个网站需要多少钱百度竞价优缺点
  • 黑龙江省建设教育协会网站首页百度官网推广
  • 免费域名网站推荐房地产销售
  • 石家庄站布局图seo站长论坛