Spring中的注解扫描

本文介绍了Spring中的注解扫描,包括使用@Component、@Service、@Repository等注解创建对象并放入容器,以及如何通过@Autowired注解自动装配。还讨论了Spring Boot的默认扫描规则和@Scope("prototype")的作用。此外,提到了@MapperScan用于扫描Mapper接口,并讲解了XML配置中的过滤规则。
摘要由CSDN通过智能技术生成

创建接口TestRepository

package ss.java.springannotationscan.repository;

public interface TestRepository {
   
    void testRepositoryMethod();
}

实现类TestRepositoryImpl

package ss.java.springannotationscan.repository.impl;

import org.springframework.stereotype.Repository;
import ss.java.springannotationscan.repository.TestRepository;

/**
 * @author XYang
 * @date 2020-07-06 19:12
 */

@Repository
public class TestRepositoryImpl implements TestRepository {
   
    /**
 public void testRepositoryMethod() {
        System.out.println("调用testRepositoryMethod方法");
    }

}

创建接口 TestService

package ss.java.springannotationscan.service.impl;

public interface TestService {
   

    void testServiceMethod();
}

实现类TestServiceImpl

package ss.java.springannotationscan.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import ss.java.springannotationscan.repository.TestRepository;
import ss.java.springannotationscan.service.impl.TestService;

/**
 * @author XYang
 * @date 2020-07-06 19:12
 */
@Scope("prototype")
@Service("service")
public class TestServiceImpl implements TestService {
   

    @Autowired
    TestRepository testRepository;

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值