Spring注解-解析

@Service

用于标注业务层组件

@Controller

用于标注控制层组件(如struts中的action)

@Repository

用于标注数据访问组件,即DAO组件

@Component

泛指组件,当组件不好归类的时候,我们可以使用这个注解进行标注

@Autowired

后不需要getter()和setter()方法,Spring也会自动注入

@Configuration

提供spring配置类,一般与@Bean一起搭配使用

@EnableAutoConfiguration

能够自动配置spring的上下文,试图猜测和配置你想要的bean类,通常会自动根据你的类路径和你的bean定义自动配置

@ComponentScan

会自动扫描指定包下的全部标有@Component的类,并注册成bean,当然包括@Component下的子注解@Service,@Repository,@Controller

@ResponseBody

用该注解修饰的函数,会将结果直接填充到HTTP的响应体中,一般用于构建RESTful的api

@RestController

@ResponseBody和@Controller的合集

@RequestMapping

提供路由信息,负责URL到Controller中的具体函数的映射

@Import

用来导入其他配置类

@ImportResource

用来加载xml配置文件

猜你喜欢

转载自blog.csdn.net/jishanwang/article/details/85771383