【发布时间】:2015-07-02 17:17:27
【问题描述】:
我想将 spring xml 转换为 java 配置。
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
default-autowire="byName">
<bean name="car" type="Car" />
<bean name="tire" type="Tire" />
</beans>
我有两个课程:汽车和轮胎。
public class Tire {
private String age;
}
public class Car {
private Tire tire;
// Spring calls this setter because default-autowire="byName" of xml configuration
public void setTire(Tire newTire) {
this.tire = newTire;
}
}
我不使用@Inject 或@Autowired 注释,但是spring autowires 并且它可以工作。 如何将 xml 更改为 java 配置而不修改 Car 和 Tire 类?
提前致谢。
【问题讨论】:
标签: spring autowired spring-java-config