您的位置:首页 > 编程语言 > Java开发

SSH或SHSpringMVC下采用spring的Annotation配置dao,service,controller(便于团队开发,各自修改自己的annotation)

2014-03-23 23:35 573 查看
使用此功能的前提必须是Spring3.0或以上版本。

在和数据库连接的spring配置文件中修改,此文的项目基础来源于http://blog.csdn.net/needkane/article/details/21410805

我们在applicationContext-hibernate.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"
    xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.0.xsd">
加入下面的配置,设置允许使用Annotation,并设置Annotation作用的包范围,其中要包括dao.impl,service.impl和action。

<context:annotation-config></context:annotation-config>

<context:component-scan
base-package="com.kane.action,com.kane.back.service.impl,com.kane.dao.impl">
</context:component-scan>
接下来数据源等配置和以前一样,这样代替了xml配置

dao.impl类的声明

// 表示该类自动配置成为一个Spring的<bean>,id为类名首字母小写
@Component
service类的声明

@Service

action类的声明

// 也表示是一个<bean>
@Controller
// 不使用单例设计
@Scope(value =
"prototype")
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐