---
title: "spring mvc 用到的注解"
author: "喧嚣求静"
date: "2011-11-28T11:35:42Z"
tags: []
categories: ["Web前端"]
slug: "spring-mvc"
draft: false
lastmod: "2011-11-28T15:22:01Z"
id: 1280674
url: "https://913.iteye.com/blog/1280674"
---

在实际项目中很少用全部用配置文件到注册Bean，映射MVC等，全用注解，这样可以减少很多配置文件，节约开发时间。
spring mvc 用到的注解：所有注解使用场合必须开启spring 组件扫描

```xml

<context:component-scan base-package="com.web"/>

```

在Action中用到的
@Controller--此注解用于标记在spring中由Bean工厂管理Action，并标明此类为MVC中的Controller且不用显示实现Controller接口。
@RequestMapping--此注解用于标记在spring MVC中进行映射，相当于在配置文件配置请求Pathr 映射，

```java

@Controller
public class BodyAction {

	@RequestMapping
	public void execute(Model model) {
…………
}

```


通用
@Autowired
在service层用到
@Service
@Transactional
在持久层用到的
@Repository
@Entity
[详解 Spring 3.0 基于 Annotation 的依赖注入实现](http://www.ibm.com/developerworks/cn/opensource/os-cn-spring-iocannt/index.html?ca=drs-tp4608)