java学习笔记

spring学习笔记(持续更新)

前言

由于快到毕业季,本人无可奈何ssm的水平太差,所以决定开始写博客。目前工作还是没着落。只能够一边学习一边找了。希望能坚持下去。

注解注入

首先进入spring官网的spring framework(spring框架)

附网址(https://docs.spring.io/spring-framework/docs/current/spring-framework-reference/core.html#beans-definition)

直接看spring framework的指导手册的core部分。先转到1.9. Annotation-based Container Configuration(基于容器配置的注解)部分。1.9节开头便阐述了用XML注入和注解注入的的不同点,接下来正式开始学习IOC容器。

1.全注解方式

1.1基本注解

先转到1.10.3. Automatically Detecting Classes and Registering Bean Definitions(自动检测类及注册bean定义)

首先介绍的是一个基本的注解,能够替代XML的注入方式(扫描指定类路径里的bean),下面是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"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        https://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        https://www.springframework.org/schema/context/spring-context.xsd">

    <context:component-scan base-package="org.example"/>

</beans>
@Configuration
@ComponentScan(basePackages = "org.example",useDefaultFilters=false)
public class AppConfig  {
    // ...
}

useDefaultFilters=false 可以有效地将这个自动扫描组件的功能禁用掉。

@Configuration @ComponentScan (basePackages = “”)这两个注解适配以下四个注解,可以从指定类包里扫描并注册。

@Component(组件)

@Repository(仓库)

@Service(服务)

@Controller(控制器)

1.2注解的具体用法

Mybatis学习笔记(同)

杂记

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值