对于这个spring在实际开发的过程中
我们是不会去将这个配置文件当中的这个全类名去直接拿掉的
但是我们在debug的过程当中我们可以知道
这个全类名是可以去拿掉的
但是这样的话我们的spring中运行的时候
会自己的底层自动的处理
#0,#1,#2 and so on
这样在不同的配置文件中,还是会存在相关的标号进行区分
Car类
package com.hspedu.spring.homework01;
import java.math.BigDecimal;
/**
* @author xiaowang
* @creat 2024/7/14 10:06
* @Description Java Lotus
*/
public class Car {
private Integer id;
private String name;
private BigDecimal price;
//用于Java反射
public Car() {
}
public Car(Integer id, String name, BigDecimal price) {
this.id = id;
this.name = name;
this.price = price;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public BigDecimal getPrice() {
return price;
}
public void setPrice(BigDecimal price) {
this.price = price;
}
@Override
public String toString() {
return "Car{" +
"id=" + id +
", name='" + name + '\'' +
", price=" + price +
'}';
}
}
测试类
package com.hspedu.spring.test;
import com.hspedu.spring.homework01.Car;
import org.junit.jupiter.api.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* @author xiaowang
* @creat 2024/7/14 10:11
* @Description Java Lotus
*/
public class CarTest {
@Test
public void getCar(){
ApplicationContext ioc =
new ClassPathXmlApplicationContext("beans.xml");
Car car = (Car) ioc.getBean("car");
System.out.println(car);
System.out.println(car.getId());
System.out.println(car.getName());
System.out.println(car.getPrice());
System.out.println(car.getClass());
}
}
在这个里面我们也可以单独去写一份容器配置文件
这样的话,对于我们前期学习,每一个类可以去单独创建一个相关的配置文件
这样的话我们就在get中获取这个xml文件
同时需要注意的点就是
这个无参构造器的提供是十分的重要的
这样就是在初始化的时候提供了一个相应的无参构造器
这样的使用,就让我们的无参构造器由我们的Java反射产生
如果在无参构造器中我们提前设定了一段话的话,我们再启动时,调用相关的配置时,这个无参构造器回去率先执行