hello!python!

spring IOC 注解@Resource

1.@Resource(重要)
a)加入 :j2ee/common-annotations.jar
b)默认按名称,名称找不到,按类型

默认按照名称setName1到xml中找和id相同的,没有的话再找和SetName类型一样的

public class HelloWorld {
    SetName setName;
    @Resource
       public void setMessage(SetName setName1){
        this.setName=setName1;
        System.out.println("setmessage");
         setName1.getSetName() ;
       }
}
<?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:context="http://www.springframework.org/schema/context"    
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.0.xsd">

   <context:annotation-config/>
   <bean id="helloWorld" class="com.yibai.HelloWorld">
<!--      <property name="message" value="Hello World!"/> -->
   </bean>
    <bean id="setName1" class="com.yibai.SetName">
    </bean>
    <bean id="setname12" class="com.yibai.SetName">
    </bean>
</beans>

 

posted @ 2015-03-31 21:28  你坚持了吗  阅读(486)  评论(0编辑  收藏  举报
hello!python!