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>

 

相关文章:

  • 2021-07-07
  • 2022-03-05
  • 2021-09-17
  • 2021-10-17
  • 2022-02-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-05-15
  • 2022-12-23
  • 2021-12-25
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案