1.创建Maven项目,项目名称springdemo49,如图所示

2.配置Maven,修改项目中的pom.xml文件,修改内容如下

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>1.0.0</modelVersion><groupId>shequ</groupId><artifactId>springdemo13</artifactId><version>0.0.1-SNAPSHOT</version><properties><java.version>1.7</java.version><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding></properties><repositories><repository><id>codelds</id><url>https://code.lds.org/nexus/content/groups/main-repo</url></repository></repositories><dependencies><dependency><groupId>javax.annotation</groupId><artifactId>jsr250-api</artifactId><version>1.0</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-test</artifactId><version>4.1.4.RELEASE</version></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.10</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-core</artifactId><version>4.1.4.RELEASE</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>4.1.4.RELEASE</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-jdbc</artifactId><version>4.1.4.RELEASE</version></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.34</version></dependency></dependencies><build/>
</project>

3.在src/main/java下创建实体Bean Customer,包名(com.mycompany.shequ.bean)如图所示

4.实体Bean Customer的内容如下

package com.mycompany.shequ.bean;import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;@Component("customerBean")
public class Customer {private String name;private String email;public String getName() {return name;}public void setName(String name) {this.name = name;}public String getEmail() {return email;}@Value("#{('dengyunshuo@163.com' matches '^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)" +"*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$') ? 'dengyunshuo@163.com':'不合法'}")public void setEmail(String email) {this.email = email;}
}

5.在src/main/java下创建dao ICustomerDao,包名(com.mycompany.shequ.dao)如图所示

6.ICustomerDao的内容如下

package com.mycompany.shequ.dao;public interface ICustomerDao {public void showMe();
}

7.在src/main/java下创建ICustomerDao的实现类CustomerDaoImpl,包名(com.mycompany.shequ.dao.impl)如图所示

8.ICustomerDao的实现类CustomerDaoImpl的内容如下

package com.mycompany.shequ.dao.impl;import com.mycompany.shequ.dao.ICustomerDao;public class CustomerDaoImpl implements ICustomerDao {public void showMe() {System.out.println("I'm CustomerDaoImpl");}}

9.在src/main/java下创建业务Bean ICustomerService接口,包名(com.mycompany.shequ.service)如图所示

10.ICustomerService接口的内容如下

package com.mycompany.shequ.service;public interface ICustomerService {public void showMe();
}

11.在src/main/java下创建业务Bean ICustomerService接口的实现类CustomerServiceImpl,包名(com.mycompany.shequ.service.impl)如图所示

12.业务Bean ICustomerService接口的实现类CustomerServiceImpl的内容如下

package com.mycompany.shequ.service.impl;import org.springframework.beans.factory.annotation.Autowired;import com.mycompany.shequ.dao.ICustomerDao;
import com.mycompany.shequ.service.ICustomerService;public class CustomerServiceImpl implements ICustomerService {private ICustomerDao customerDao;public ICustomerDao getCustomerDao() {return customerDao;}@Autowiredpublic void setCustomerDao(ICustomerDao customerDao) {this.customerDao = customerDao;}public void showMe() {customerDao.showMe();}}

13.在src/main/resource下创建核心的配置文件applicationContext.xml,如图所示

14.配置文件applicationContext.xml,如图所示

<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:p="http://www.springframework.org/schema/p"xmlns:context="http://www.springframework.org/schema/context"xmlns:util="http://www.springframework.org/schema/util"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-4.0.xsdhttp://www.springframework.org/schema/utilhttp://www.springframework.org/schema/util/spring-util-4.0.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-4.0.xsd"><context:component-scan base-package="com.mycompany.shequ"><context:include-filter type="regex" expression="com.mycompany.shequ.dao.impl.*Impl"/><context:include-filter type="regex" expression="com.mycompany.shequ.service.impl.*Impl"/></context:component-scan></beans>

15.在src/test/java下创建测试文件AppTest,包名(com.mycompany.shequ.test)如图所示

16.测试文件AppTest的内容如下

package com.mycompany.shequ.test;import org.junit.Test;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.mycompany.shequ.service.ICustomerService;public class AppTest {@Testpublic void beanTest(){ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");ICustomerService customerService = (ICustomerService) context.getBean("customerServiceImpl");customerService.showMe();}
}   

17.在测试类AppTest的beanTest方法上右键运行,输出结果如图所示

转载于:https://blog.51cto.com/suyanzhu/1910297

Spring4-使用组件过滤器相关推荐

  1. Spring过滤器组件自动扫描

    在这个Spring自动组件扫描的教程,您已经了解如何使Spring自动扫描您的组件.在这篇文章中,我们将展示如何使用组件过滤器自动扫描过程. 1.过滤组件 - 包含 参见下面的例子中使用Spring  ...

  2. 【Android FFMPEG 开发】FFMPEG 交叉编译配置 ( 下载 | 配置脚本 | 输出路径 | 函数库配置 | 程序配置 | 组件配置 | 编码解码配置 | 交叉编译配置 | 最终脚本 )

    文章目录 一.FFMPEG 源码下载 解压 二.交叉编译工具 三.configure 脚本及帮助命令 四.配置 configure 脚本 五.输出目录配置 六.函数库配置 七.程序配置选项 八.组件配 ...

  3. java怎么监听多个组件,java web(五):java web三大组件之另外两个和八大监听器

    java的三大组件指Servlet.Filter.Listener.八大监听器指八个接口.前面介绍了Servlet,现在介绍一下Filter拦截器以及拦截地址的设置, Listener监听那些事件. ...

  4. Android 意图和意图过滤器(二)

    本文来自:安卓航班网 应该递交给意图处理组件的附加信息键-值对.就像一些动作伴随着特定的数据URIs类型,一些动作则伴随着特定的附加信息.比如,一个ACTION_TIMEZONE_CHANGED意图有 ...

  5. Vue过滤器-filter

    Vue中的过滤器不能替代Vue中的methods.computed或者watch,因为过滤器不改变真正的data,而只是改变渲染的结果,并返回过滤后的版本.在很多不同的情况下,过滤器都是有用的,比如尽 ...

  6. Servlet与过滤器

    Servlet Server+Applet,是一种服务器端的Java应用程序 只有当一个服务器端的程序使用了Servlet API的时候,这个服务端的程序才能称之为Servlet jsp从莫种意义上来 ...

  7. 重拾Activity(二)Intent和Intent过滤器

    目录 Intent 类型 显式 Intent 示例 隐式 Intent 示例 强制使用应用选择器 接收隐式 Intent 限制对组件的访问 常用Intent 闹钟 创建闹铃 创建定时器 显示所有闹铃 ...

  8. Intent 和 Intent 过滤器

    Intent 和 Intent 过滤器 本文内容 Intent 类型 构建 Intent 显式 Intent 示例 隐式 Intent 示例 强制使用应用选择器 接收隐式 Intent 过滤器示例 使 ...

  9. 第 19 课时:调度器的调度流程和算法介绍(木苏)

    本文将主要分享以下四个部分的内容: 调度流程 调度算法 如何配置调度器 如何扩展调度器 调度流程 调度流程概览 首先来看一下调度器流程概览图: 调度器启动时会通过配置文件 File,或者是命令行参数, ...

最新文章

  1. Linux下Socket编程
  2. HEAD元素使用集锦
  3. python【数据结构与算法】搜索初探
  4. python的time库有哪些方法_Python的time模块中的常用方法整理
  5. python gridfs_python 将图片存入mongodb,读取图片,gridfs模块
  6. Delphi XE5 for Android (八)
  7. Blazor 应用如何使用 Azure Active Directory 认证登录
  8. 300. 最长上升子序列
  9. 在大流行的世界中如何建立技术社区
  10. ORACLE 10G rman 备份脚本
  11. VB CreateObject函数
  12. java读取摄像头视屏流,Java 摄像头视频获取
  13. 校园二手交易平台项目总结 ‎2013‎年‎12‎月‎23‎日,‏‎5:57:29
  14. 测试质量保障体系的建立
  15. 希尔排序、快速排序的每一趟
  16. 线性代数学习笔记——第十二讲——求解矩阵方程
  17. php 上传绕过,文件上传验证绕过技术总结
  18. 电脑鸿蒙系统怎么连接无线网络,手提电脑怎样连接WiFi?
  19. Linux开机自动获取本机公网IP并发送至指定邮箱
  20. 通过虚拟机模拟linux操作系统

热门文章

  1. L2-006. 树的遍历-PAT团体程序设计天梯赛GPLT
  2. 蓝桥杯 ADV-108算法提高 分数统计
  3. MySQL text类型的最大长度
  4. CAT - 监控平台之装配篇
  5. 快速搭建Web环境 Angularjs + Express3 + Bootstrap3
  6. iOS设计模式——委托(delegate)
  7. Android 官方命令深入分析之android
  8. canvas绘图粒子扩散效果【原创】
  9. django-dynamic-scraper(DDS)配置中的一些问题
  10. JS 获取元素当前的样式信息