beans-annotation.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 http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd">

<!-- 指定spring IOC 容器扫描的包 -->
<!-- 可以通过 resource-pattern 指定扫描的资源 -->
<!--
<context:component-scan
base-package="com.hy.spring.beans.annotation"
resource-pattern="repository/*.class">
</context:component-scan>
-->

<!-- context:exclude-filter 子节点指定排除哪些指定表达式的组件 -->
<!-- context:include-filter 子节点指定包含哪些表达式的组件,该节点需要 use-default-filters 配合使用-->
<context:component-scan
base-package="com.hy.spring.beans.annotation"
use-default-filters="false">
<!--
<context:exclude-filter type="annotation"
expression="org.springframework.stereotype.Repository"/>
-->

<!-- <context:include-filter type="annotation"
expression="org.springframework.stereotype.Repository"/>
-->

<!-- <context:exclude-filter type="assignable"
expression="com.hy.spring.beans.annotation.repository.UserRepository"/>
-->

<context:include-filter type="assignable"
expression="com.hy.spring.beans.annotation.repository.UserRepository"/>
</context:component-scan>

</beans>

TestObject.java

package com.hy.spring.beans.annotation;

import org.springframework.stereotype.Component;

@Component
public class TestObject {

}

UserController.java

package com.hy.spring.beans.annotation.controller;

import org.springframework.stereotype.Controller;

@Controller
public class UserController {
public void execute(){
System.out.println("UserController execute....");
}
}

UserRepository.java

package com.hy.spring.beans.annotation.repository;

public interface UserRepository {
public void save();
}

UserRepositoryImpl.java

package com.hy.spring.beans.annotation.repository;

import org.springframework.stereotype.Repository;

@Repository("userRepository")
public class UserRepositoryImpl implements UserRepository{

public void save() {
System.out.println("UserRepositoryImpl save....");

}

}

UserService.java

package com.hy.spring.beans.annotation.service;

import org.springframework.stereotype.Service;

@Service
public class UserService {
public void add(){
System.out.println("UserService add...");
}
}

Spring_通过注解配置 Bean(1)的更多相关文章

  1. Spring_通过注解配置 Bean(2)

  2. [原创]java WEB学习笔记103:Spring学习---Spring Bean配置:基于注解的方式(基于注解配置bean,基于注解来装配bean的属性)

    本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...

  3. Spring(二)--FactoryBean、bean的后置处理器、数据库连接池、引用外部文件、使用注解配置bean等

    实验1:配置通过静态工厂方法创建的bean  [通过静态方法提供实例对象,工厂类本身不需要实例化!] 1.创建静态工厂类 public class StaticFactory { private st ...

  4. 通过注解配置Bean

    之前说的三种配置方式,都是使用XML配置,现在我们说说使用注解配置Bean. 这部分内容主要分为两个部分:使用注解配置Bean,使用注解配置Bean属性. 在classpath中扫描组件 组件扫描:S ...

  5. Spring(十五):通过注解配置 Bean

    在ClassPath中扫描组件 1)组件扫描(component scanning):Spring能够从classpath下自动扫描,侦测和实例化具有特定注解的组件: 2)特定组件包含: --- @C ...

  6. IDEA02 利用Maven创建Web项目、为Web应用添加Spring框架支持、bean的创建于获取、利用注解配置Bean、自动装配Bean、MVC配置

    1 环境版本说明 Jdk : 1.8 Maven : 3.5 IDEA : 专业版 2017.2 2 环境准备 2.1 Maven安装及其配置 2.2 Tomcat安装及其配置 3 详细步骤 3.1 ...

  7. Spring IOC机制之使用注解配置bean

    一. 通过注解配置bean 1.1       概述 相对于XML方式而言,通过注解的方式配置bean更加简洁和优雅,而且和MVC组件化开发的理念十分契合,是开发中常用的使用方式. 1.2       ...

  8. 14Spring通过注解配置Bean(2)

    下面将对13Spring通过注解配置Bean(1)的中Repository.Service.Controller通过注解方式来建立关联. <context:component-scan>元 ...

  9. 13Spring通过注解配置Bean(1)

    配置Bean的形式:基于XML文件的方式:基于注解的方式(基于注解配置Bean:基于注解来装配Bean的属性) 下面介绍基于注解的方式来配置Bean. ——组件扫描(component scannin ...

随机推荐

  1. pycharm 相关设置问题

    pycharm设置自动换行 file→settings→Editor→General→勾选 Use soft wraps in eitor → ok

  2. sublime text3 插件CTags

    1.打开Sublime Text 2/3软件,在Preferences(设置)菜单中打开Package Control(插件管理器)打开菜单后找到install packages,搜索ctags, 回 ...

  3. hiho一下第107周《Give My Text Back》

    题目链接:传送门 题目大意:给你多组格式不标准的字符串句子,要你恢复到标准格式(单词中间只有一个空格或者一个逗号一个空格,句子的首字母大写其他小写,遇到回车也要换行) 题目思路:直接按题意模拟,注意几 ...

  4. 广药帅气外教~看妹纸如何HOLD住

    看他吉他弹的好,看来我要努力练习我的吉他了,一个月了没有任何长进啊. shit~!

  5. StackExchange.Redis性能调优

    大家经常出现同步调用Redis超时的问题,但改成异步之后发现错误非常少了,但却可能通过前后记日志之类的发现Redis命令非常慢. PS: 以后代码都在Windows bash中运行,StackExch ...

  6. ubuntu 安装低版本firefox

    firefox 57以后很多插件不支持了,ubuntu16自带火狐版本59,想换回56. 1.下载想换回的版本 https://ftp.mozilla.org/pub/mozilla.org/fire ...

  7. javascript中innerHTML的问题

    获取document.getElementById()时,使用innerHTML获取标签获取内容,要注意: 1.要让内容先加载完,才可以使用,不然获取的是空,使用:window.onload = .. ...

  8. UIButton+Block

    UIButton的一个Category,使用block处理UIControlEvent事件,如常用的TouchUpInside等.代码非原创,也是从网上看到的,用到了实际项目中,目前还没发现什么问题. ...

  9. django博客项目11

    .....................

  10. 【我的Android进阶之旅】Realm数据库学习资料汇总(持续更新)

    介绍 realm是一个跨平台移动数据库引擎,支持iOS.OS X(Objective-C和Swift)以及Android. 2014年7月发布.由YCombinator孵化的创业团队历时几年打造,是第 ...