Spring 注解Annotation

特别简单,就是一个最常用的,其他不常用的就不说了

在Dao层的class上加一句

@Component("...")       名字

然后在service中的set方法上加一句

@Resource("...")          与前一个名字相对应

当然此时的Service的class上也要加一句@Component("...")

这样我们的spring配置文件就简单的多了

<?xml version="1.0" encoding="UTF-8"?>

-<beans xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans">

<context:annotation-config/>

<context:component-scan base-package="com.bjsxt"/>

</beans>

注意上面那句要加上,它的意思是,容器扫面哪个包,扫描这个包下面的文件,当发现注解时,它就会调用其中的方法

posted @ 2014-06-08 16:43  刘尊礼  阅读(87)  评论(0)    收藏  举报