注解开发

先看一看之前的bean的做法:

所谓注解开发,当然就要用到注解啊,就是在BookDao接口的实现类里面进行注解的定义

如图所示:

而在.xml文件里面,就需要进行这样一个操作:

注解当然不会只是在这里方便啦!--可以直接将.xml文件改成注解形式,实现纯注解开发

一般情况下,会直接在接口实现类那里加入@Conponent,或者使用@Service/@Repository/@Controller细化代替

然后,重点在这里:之前使用的是.xml文件进行注解开发,这里会给出一种新的方式去实现纯注解开发:创建一个java文件,在java文件里面使用注解

这个注解,主要是为了表示该java文件就是一个配置类:

这个注解,主要是为了指定到某个地方:

当然,在可执行的java文件里面,我们需要将原来的这个形式:(读配置文件)

ApplicationContext ctx=new ClassPathXmlApplicationContext("ApplicationContext.xml");

改成这个形式:(读配置类)

ApplicationContext ctx1=new AnnotationConfigApplicationContext(StringScan.class);

以上就是纯注解开发发生的基本变化啦!

Spring--注解开发定义Bean的更多相关文章

  1. Java开发学习(十)----基于注解开发定义bean 已完成

    一.环境准备 先来准备下环境: 创建一个Maven项目 pom.xml添加Spring的依赖 <dependencies>    <dependency>        < ...

  2. spring注解开发:bean的作用域与懒加载

    1.bean的作用域 1.新建一个maven工程,添加如下依赖 <dependency> <groupId>org.springframework</groupId> ...

  3. spring注解开发中常用注解以及简单配置

    一.spring注解开发中常用注解以及简单配置 1.为什么要用注解开发:spring的核心是Ioc容器和Aop,对于传统的Ioc编程来说我们需要在spring的配置文件中邪大量的bean来向sprin ...

  4. Spring注解开发-全面解析常用注解使用方法之生命周期

    本文github位置:https://github.com/WillVi/Spring-Annotation/ 往期文章:Spring注解开发-全面解析常用注解使用方法之组件注册 bean生命周期 ​ ...

  5. spring注解开发:容器中注册组件方式

    1.包扫描+组件标注注解 使用到的注解如下,主要针对自己写的类 @Controller @Service @Repository @Component @ComponentScan 参考 spring ...

  6. Spring注解开发系列Ⅵ --- AOP&事务

    注解开发 --- AOP AOP称为面向切面编程,在程序开发中主要用来解决一些系统层面上的问题,比如日志,事务,权限等待,Struts2的拦截器设计就是基于AOP的思想,横向重复,纵向抽取.详细的AO ...

  7. 浅尝Spring注解开发_自定义注册组件、属性赋值、自动装配

    Spring注解开发 浅尝Spring注解开发,基于Spring 4.3.12 包含自定义扫描组件.自定义导入组件.手动注册组件.自动注入方法和参数.使用Spring容器底层组件等 配置 @Confi ...

  8. 浅尝Spring注解开发_Bean生命周期及执行过程

    Spring注解开发 浅尝Spring注解开发,基于Spring 4.3.12 包含Bean生命周期.自定义初始化方法.Debug BeanPostProcessor执行过程及在Spring底层中的应 ...

  9. 浅尝Spring注解开发_AOP原理及完整过程分析(源码)

    浅尝Spring注解开发_AOP原理及完整过程分析(源码) 浅尝Spring注解开发,基于Spring 4.3.12 分析AOP执行过程及源码,包含AOP注解使用.AOP原理.分析Annotation ...

  10. Spring注解开发_Spring容器创建概述

    浅尝Spring注解开发_Spring容器创建概述 浅尝Spring注解开发,基于Spring 4.3.12 概述Spring容器创建的过程,包括12个方法的执行 浅尝Spring注解开发_自定义注册 ...

随机推荐

  1. go: go.mod file not found in current directory or any parent directory; see 'go help mod 解决

    go: go.mod file not found in current directory or any parent directory; see 'go help mod go:在当前目录或任何 ...

  2. 你不知道的JavaScript--作用域

                                                              用简单的代码 展示代码的魅力 1.在浏览器里,在全局范围内,this等价于windo ...

  3. vue的易错点合集

    关于vue的操作,可以借鉴到一些Ajax的方法和思路,但是因为语法的不一样,所以易错点多在语法. 第一步要引用相对的方法 div的id名称应该与下文的el名称一致 挂载方法created,相当于aja ...

  4. 微信浏览器h5页面开发遇到问题

    1.ios不支持window.open(),要创建a链接 let elink = document.createElement('a'); elink.href = baseURL+'/onlineC ...

  5. WKWebView与JS的交互

    转载:https://www.jianshu.com/p/253e76a74b38 用普通的UIWebView和JS交互 大概核心代码是这样的 - (void)setupWebView{ self.w ...

  6. find_in_set使用:匹配按逗号分隔后的内容

    SELECT  * FROM `tb_test` WHERE c_id ='123' AND create_time LIKE '2021-06-03%'  AND find_in_set('A362 ...

  7. nodejs 配置国内镜像

    npm config set registry https://registry.npm.taobao.org npm config set disturl https://npm.taobao.or ...

  8. tomcat8.5.55启动失败service tomcat start 报错

    问题描述: Neither the JAVA_HOME nor the JRE_HOME environment variable is defined At least one of these e ...

  9. Python+Django(4)——创建其他网页(模板继承)

    模板继承: 1,修改主页 父模板:抽取通用元素,在index.html同级目录下新建base.html <p> <a href="{% url 'learning_logs ...

  10. 如何卸载inventor 2023?怎么把inventor彻底卸载删除干净重新安装的方法【转载】

    inventor 2023卸载重新安装方法,使用清理卸载工具箱完全彻底删除干净inventor 2023各种残留注册表和文件.inventor 2023显示已安装或者报错出现提示安装未完成某些产品无法 ...