• 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;
    }
    
    
    }
  • 相关阅读:
    缓动公式整理(附:C#实现及WPF原版对比)
    [C#] (原创)一步一步教你自定义控件——02,ScrollBar(滚动条)
    连线
    2020.10.18:YC中学模拟赛
    【并查集】一种与时间赛跑的巧妙算法
    SpringBoot-启动流程
    Java中的ReentrantLock锁
    Tomcat-如何用线程池处理http并发请求
    Tomcat-如何建立连接获取http请求
    关于数据结构
  • 原文地址:https://www.cnblogs.com/saifei1125/p/11927608.html
Copyright © 2020-2023  润新知