Spring内部Bean利用set注入简单数据类型测试-----Spring框架



    
    
    
        
        
    
    
        
            
            
        
    
    
        
        
        
        
    
    
        
        
        
        
        
        
        
        
        
        
        
        
    


    
    
    
        
        
    
    
        
            
            
        
    
    
        
        
        
        
    
    
        
        
        
        
        
        
        
        
        
        
        
        
    
package com.powernode.spring6.Bean;

public class User
{
    //String是简单类型,int也是简单类型
    private String username;
    private int age;
    private String password;
    public void setUsername(String username) {
        this.username = username;
    }
    public void setAge(int age) {
        this.age = age;
    }
    public void setPassword(String password) {
        this.password = password;
    }
    @Override
    public String toString() {
        return "User{" +
                "username='" + username + '\'' +
                ", age=" + age +
                ", password='" + password + '\'' +
                '}';
    }
}
package com.powernode.spring6.Bean;

public class User
{
    //String是简单类型,int也是简单类型
    private String username;
    private int age;
    private String password;
    public void setUsername(String username) {
        this.username = username;
    }
    public void setAge(int age) {
        this.age = age;
    }
    public void setPassword(String password) {
        this.password = password;
    }
    @Override
    public String toString() {
        return "User{" +
                "username='" + username + '\'' +
                ", age=" + age +
                ", password='" + password + '\'' +
                '}';
    }
}
package com.powernode.spring6.Bean;

import java.util.Date;

public class SimpleValueType
{
    private int age;
    private Integer ages;
    private boolean flag;
    private Boolean F;
    private char c;
    private Character character;
    private Seasons seasons;
    private String username;
    private Class clazz;
    private Date birthday;

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }
    @Override
    public String toString() {
        return "SimpleValueType{" +
                "age=" + age +
                ", ages=" + ages +
                ", flag=" + flag +
                ", F=" + F +
                ", c=" + c +
                ", character=" + character +
                ", seasons=" + seasons +
                ", username='" + username + '\'' +
                ", clazz=" + clazz +
                ", birthday=" + birthday +
                '}';
    }
    public void setAge(int age) {
        this.age = age;
    }

    public void setAges(Integer ages) {
        this.ages = ages;
    }

    public void setFlag(boolean flag) {
        this.flag = flag;
    }

    public void setF(Boolean f) {
        F = f;
    }

    public void setC(char c) {
        this.c = c;
    }

    public void setCharacter(Character character) {
        this.character = character;
    }

    public void setSeasons(Seasons seasons) {
        this.seasons = seasons;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public void setClazz(Class clazz) {
        this.clazz = clazz;
    }
}
package com.powernode.spring6.Bean;

import java.util.Date;

public class SimpleValueType
{
    private int age;
    private Integer ages;
    private boolean flag;
    private Boolean F;
    private char c;
    private Character character;
    private Seasons seasons;
    private String username;
    private Class clazz;
    private Date birthday;

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }
    @Override
    public String toString() {
        return "SimpleValueType{" +
                "age=" + age +
                ", ages=" + ages +
                ", flag=" + flag +
                ", F=" + F +
                ", c=" + c +
                ", character=" + character +
                ", seasons=" + seasons +
                ", username='" + username + '\'' +
                ", clazz=" + clazz +
                ", birthday=" + birthday +
                '}';
    }
    public void setAge(int age) {
        this.age = age;
    }

    public void setAges(Integer ages) {
        this.ages = ages;
    }

    public void setFlag(boolean flag) {
        this.flag = flag;
    }

    public void setF(Boolean f) {
        F = f;
    }

    public void setC(char c) {
        this.c = c;
    }

    public void setCharacter(Character character) {
        this.character = character;
    }

    public void setSeasons(Seasons seasons) {
        this.seasons = seasons;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public void setClazz(Class clazz) {
        this.clazz = clazz;
    }
}
import com.powernode.spring6.Bean.SimpleValueType;
import com.powernode.spring6.Bean.User;
import com.powernode.spring6.service.OrderService;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.Date;

public class SpringDITest
{
    public static void main(String[] args) {
        System.out.println(new Date());
    }
    @Test
    public void TestSetDI()
    {
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("set-di.xml");
        OrderService OrderService = applicationContext.getBean("OrderService", OrderService.class);
        OrderService.generate();
        OrderService = applicationContext.getBean("OS",OrderService.class);
        OrderService.generate();
        User user = applicationContext.getBean("User", User.class);
        System.out.println(user);
        SimpleValueType simpleValueType = applicationContext.getBean("SimpleValueType",SimpleValueType.class);
        System.out.println(simpleValueType);
    }
}
import com.powernode.spring6.Bean.SimpleValueType;
import com.powernode.spring6.Bean.User;
import com.powernode.spring6.service.OrderService;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.Date;

public class SpringDITest
{
    public static void main(String[] args) {
        System.out.println(new Date());
    }
    @Test
    public void TestSetDI()
    {
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("set-di.xml");
        OrderService OrderService = applicationContext.getBean("OrderService", OrderService.class);
        OrderService.generate();
        OrderService = applicationContext.getBean("OS",OrderService.class);
        OrderService.generate();
        User user = applicationContext.getBean("User", User.class);
        System.out.println(user);
        SimpleValueType simpleValueType = applicationContext.getBean("SimpleValueType",SimpleValueType.class);
        System.out.println(simpleValueType);
    }
}

你可能感兴趣的:(Spring框架,JAVA随手写,spring,java,开发语言,后端,eclipse)