zoukankan      html  css  js  c++  java
  • spring 创建三种创建对象的方法

    spring 创建三种创建对象的方法

    User类

     
     
     
    x
     
     
     
     
    public class User {
        private String name;
        private Integer age;
        private TestObj testObj;
        public TestObj getTestObj(){
            return new TestObj();
        }
    }
     

    getTestObj类

     
     
     
     
     
     
     
     
    public class TestObj {
        private String Test;
    }
     

    xml配置

     
     
     
    xxxxxxxxxx
     
     
     
     
    <!--使用默认方法构建-->
    <bean id="user" class="com.test.User"/>
    <!--使用工厂内的普通方法创建-->
    <bean id="testObj" factory-bean="user" factory-method="getTestObj"/>
    <!--通过静态方法-->
    <bean id="staticGetTestObj" class="com.chexd.User" factory-method="getStaticTestObj"/>
     

    @Test(比如用第三方的jar包 放到spring工厂内)

     
     
     
    x
     
     
     
     
            ApplicationContext context = new ClassPathXmlApplicationContext( "spring.xml" );
            TestObj testObj = context.getBean( "testObj", TestObj.class );
            System.out.println(testObj);
            TestObj testStaticObj = context.getBean( "staticGetTestObj", TestObj.class );
            System.out.println(testStaticObj);
     
  • 相关阅读:
    决策树
    交叉熵与softmax
    集成学习
    SVM算法
    蒙特卡罗方法
    K近邻--KNN
    K-Means聚类
    DBSCAN密度聚类
    Bagging、随机森林
    支持向量机SVM
  • 原文地址:https://www.cnblogs.com/chengfengchi/p/14420094.html
Copyright © 2011-2022 走看看