• spring setter注入


    Bean.xml

    <?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"   
        xmlns:aop="http://www.springframework.org/schema/aop"       
        xmlns:tx="http://www.springframework.org/schema/tx"         
        xmlns:util="http://www.springframework.org/schema/util"         
        xmlns:p="http://www.springframework.org/schema/p"               
        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    
                            http://www.springframework.org/schema/aop                               
                            http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
                            http://www.springframework.org/schema/tx                            
                            http://www.springframework.org/schema/tx/spring-tx-3.0.xsd                      
                            http://www.springframework.org/schema/util                          
                            http://www.springframework.org/schema/util/spring-util-3.0.xsd"
                            default-init-method="defaultInit" default-destroy-method="defaulfDestroy">  
         
       <bean id="all_OP" class="service.All_OP">
               <!--  <property name="all_atomic" ref="all_atomic"></property> -->
               <constructor-arg ref="all_Atomic"></constructor-arg>
       </bean> 
          
       <bean id="all_Atomic" class="service.All_Atomic">
       </bean> 
        
        <!-- <context:component-scan base-package="service,test" /> -->
    </beans>

    All_Atomic.java  随便

    All_OP.java

    public class All_OP extends TestBase{
        private All_Atomic all_atomic;
        public All_OP(All_Atomic all_atomic) {         
            // TODO Auto-generated constructor stub
            this.all_atomic=all_atomic;
        }

    TestBase.java

    public class TestBase  {
        private ClassPathXmlApplicationContext context;
        private String springXmlPath;
        
        public TestBase() {
            springXmlPath="classpath*:Beans.xml";
        }
      @BeforeClass
      public void beforeClass() {
          context=new ClassPathXmlApplicationContext(getSpringXmlPath().split("[,\s]+"));
          //context.start();
      }
    
      @SuppressWarnings("unchecked")
    public <T extends Object> T getBean(String beanId) {
        return (T)context.getBean(beanId);
      } 
      
    
    public <T extends Object> T getBean(Class<T> clazz) {
        return (T)context.getBean(clazz);
    }
    
    public void setSpringXmlPath(String springXmlPath) {
        this.springXmlPath = springXmlPath;
    }
    public String getSpringXmlPath() {
        return springXmlPath;
    }
    
    
    }
  • 相关阅读:
    do while 后面要加分号,你大爷的
    ATS push cache 测试
    ATS (apache traffic server) http_ui 设置与使用
    chrome 开发者工具使用一例
    beautiful soup 遇到class标签的值中含有空格的处理
    virtualbox sharefolder mount fail
    从wait角度调优
    Service Broker入门
    数据库建立初步
    只读账号设置-db_datareader
  • 原文地址:https://www.cnblogs.com/saifei1125/p/11927608.html
Copyright © 2020-2023  润新知