标签:core ogg color utf-8 xsd 注解 ase public junit
Spring的注解是在Spring2.5的版本中引入的,目的简化XML配置。在企业开发过程中使用注解的频率非常高,但是学习注解的前提是大家一定要对Spring基于XML配置要熟悉,这是我个人建议,因为在Spring2.0的版本时候是没有出现注解的使用
1. Spring常用注解如下
2. 使用Spring注解的时候一定关注Spring框架需要加入的包【很重要】,我们这里以spring4.0.3版本为例来介绍
3. @Component注解
<?xml version="1.0" encoding="UTF-8"?> <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/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <context:component-scan base-package="com.gxa.spring.day02"></context:component-scan> </beans>
package com.gxa.spring.day02; import org.springframework.stereotype.Component; @Component public class StudentAnnotation { }
package com.gxa.spring.test; import org.junit.Test; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import com.gxa.spring.day02.StudentAnnotation; public class Test02 { @Test public void m06() { ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml"); StudentAnnotationstudentAnnotation = context.getBean("studentAnnotation", StudentAnnotation.class); System.out.println(studentAnnotation.hashCode()); } }
4. 除了@Component注解,Spring容器提供了3个功能和@Component注解等同。它们分别是用于对Dao,Service及Web层的Controller进行注解
标签:core ogg color utf-8 xsd 注解 ase public junit
原文地址:http://www.cnblogs.com/liuyangjava/p/6671172.html