Spring_通过注解配置 Bean(1)




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)的更多相关文章
- Spring_通过注解配置 Bean(2)
- [原创]java WEB学习笔记103:Spring学习---Spring Bean配置:基于注解的方式(基于注解配置bean,基于注解来装配bean的属性)
本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...
- Spring(二)--FactoryBean、bean的后置处理器、数据库连接池、引用外部文件、使用注解配置bean等
实验1:配置通过静态工厂方法创建的bean [通过静态方法提供实例对象,工厂类本身不需要实例化!] 1.创建静态工厂类 public class StaticFactory { private st ...
- 通过注解配置Bean
之前说的三种配置方式,都是使用XML配置,现在我们说说使用注解配置Bean. 这部分内容主要分为两个部分:使用注解配置Bean,使用注解配置Bean属性. 在classpath中扫描组件 组件扫描:S ...
- Spring(十五):通过注解配置 Bean
在ClassPath中扫描组件 1)组件扫描(component scanning):Spring能够从classpath下自动扫描,侦测和实例化具有特定注解的组件: 2)特定组件包含: --- @C ...
- 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 ...
- Spring IOC机制之使用注解配置bean
一. 通过注解配置bean 1.1 概述 相对于XML方式而言,通过注解的方式配置bean更加简洁和优雅,而且和MVC组件化开发的理念十分契合,是开发中常用的使用方式. 1.2 ...
- 14Spring通过注解配置Bean(2)
下面将对13Spring通过注解配置Bean(1)的中Repository.Service.Controller通过注解方式来建立关联. <context:component-scan>元 ...
- 13Spring通过注解配置Bean(1)
配置Bean的形式:基于XML文件的方式:基于注解的方式(基于注解配置Bean:基于注解来装配Bean的属性) 下面介绍基于注解的方式来配置Bean. ——组件扫描(component scannin ...
随机推荐
- Arcgis for Js之GeometryService实现測量距离和面积
距离和面积的測量时GIS常见的功能.在本节,讲述的是通过GeometryService实现測量面积和距离.先看看实现后的效果: watermark/2/text/aHR0cDovL2Jsb2cuY3N ...
- Date类、DateFormat类和Calendar类
1.Date类 常用方法:long getTime():返回1970年1月1日00:00:00以来的毫秒值,把日期对象转换成毫秒值 2.DateFormat类 DateFormat类是日期/时间格式化 ...
- jQuery的validate验证插件使用方法
(1)默认校验规则(1)required:true 必输字段(2)remote:"check.php" 使用ajax方法调用check.php验证输入值(3)email:true ...
- Codevs (3657括号序列 )
题目链接:传送门 题目大意:中文题,略 题目思路:区间DP 这个题是问需要添加多少个括号使之成为合法括号序列,那么我们可以先求有多少合法的括号匹配,然后用字符串长度减去匹配的括号数就行 状态转移方程主 ...
- iOS 状态栏更改为白色
如果觉得在iOS 7启动期间状态栏黑色不合你意,以下方法可改变Status bar style成白色 在工程的plist添加 Status bar style,改变style值 默认是Gray sty ...
- Java模拟并发
=========================one============================= public class Bingfa { public static void m ...
- scrapy工程创建及pycharm运行
1.通过命令行创建scrapy工程项目 scrapy startproject (工程名) scrapy startproject myxml 2.利用爬虫模板设置爬虫文件 在这个过程中我们可以先利用 ...
- Oracle重做日志REDO
什么是重做? 重做日志包含所有数据产生的历史改变记录. 重做日志目的是保证数据的安全,如果数据因特殊原因没有写到磁盘上,可以通过重做日志来恢复. 重做日志文件通常用于 恢复(实例恢复和介质恢复) 日志 ...
- 直播未来属于RTMP还是HTTP
直播未来属于RTMP还是HTTP? - Tinywan - 博客园 https://www.cnblogs.com/tinywan/p/6122065.html 直播未来属于RTMP还是HTTP? H ...
- xshell上传下载文件
上传文件到服务器rz 从服务器下载文件sz