Edited at

DTDファイルの属性変更例

More than 3 years have passed since last update.

<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd" [<!ATTLIST bean singleton (true | false) "false">]>

■例:

t1.xml

    <?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="triangleAlone" class="dto.Triangle" >
</bean>
<import resource="t1_1.xml" />
</beans>


t1_1.xml

    <?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd" [<!ATTLIST bean singleton (true|false) "false">]>
<beans>
<bean id="triangleParent" class="dto.Triangle">
</bean>

<bean id="triangleChild" class="dto.Triangle" parent="triangleParent">
</bean>
</beans>

確認

```java

import org.springframework.context.ApplicationContext;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import dto.Triangle;

public class Test {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("dto/t1.xml");

for (int i = 0; i < 3; i ++) {
Triangle triangle1 = (Triangle) context.getBean("triangleAlone");
System.out.println(triangle1);
}

for (int i = 0; i < 3; i ++) {
Triangle triangle1 = (Triangle) context.getBean("triangleParent");
System.out.println(triangle1);
}

for (int i = 0; i < 3; i ++) {
Triangle triangle2 = (Triangle) context.getBean("triangleChild");
System.out.println(triangle2);
}
}
}