首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

spring引语和组件扫描配置

2012-06-27 
spring注解和组件扫描配置spring的部分bean在xml中配置,但我觉得action,service,dao这些完全没必要在xml中

spring注解和组件扫描配置

spring的部分bean在xml中配置,但我觉得action,service,dao这些完全没必要在xml中配置,一来如果IDE支持不好容易配置错误,二来这些类多起来后简直就没办法看。故采用注解配置这三层,基本配置配好后可以不动xml配置文件了。

一、首先添加注解和组件扫描配置。在spring配置文件中加入:

<!-- 注解支持 --><context:annotation-config/><!-- 组件扫描com.test目录下的所有文件 --><context:component-scan base-package="com.test"/>


二、在action,service,dao这三层的实现类中分别对应注解Controller,Service,Repository如果你不想逻辑上有所区分就直接用Component。

代码类似于:
@Controllerpublic class myAction extends BaseAction{    ......}@Servicepublic class myService extends BaseService{    ......}@Repositorypublic class myDao extends BaseDao{    ......}@Componentpublic class myXXX extends BaseXXX{    ......}

热点排行