2008年4月21日

Spring Framework FileSystemXmlApplicationContext

Spring Framework

// spring.xml

<?xml version="1.0" encoding="UTF-8"?>
<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.xsd">
<bean id="featureDescriptor" class="java.beans.FeatureDescriptor">
<property name="shortDescription" value="hello"/>
<property name="displayName" value="hello world"/>
<property name="name" value="test"/>
</bean>
</beans>

// Main.java

import java.beans.FeatureDescriptor;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

public class Main {
public static void main(String[] args) {
ApplicationContext context =
new FileSystemXmlApplicationContext("spring.xml");
FeatureDescriptor fd =
(FeatureDescriptor)context.getBean("featureDescriptor");
System.out.println(fd.getName());
System.out.println(fd.getDisplayName());
}
}

/* Stdout
test
hello world
*/

沒有留言:

網誌存檔