sp; }
@Override public void afterPropertiesSet() { System.out.println("属性设置完后执行该方法"); }
@Override public void destroy() { System.out.println("结束前执行一些清理工作"); } }
在Spring bean配置文件中定义该bean:(配置文件名称为SpringConfig.xml)
[html] view plaincopyprint? 01.<?xml version="1.0" encoding="UTF-8"?> 02. 03.<beans xmlns="http://www.springframework.org/schema/beans" 04. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 05. xsi:schemaLocation="http://www.springframework.org/schema/beans 06. http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> 07. 08. <bean id="simple" class="SimpleBean"> 09. <property name="name" value="I'm a Simple Bean"> 10. </bean> 11.</beans> <?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-3.0.xsd">
<bean id="simple" class="SimpleBean"> <property name="name" value="I'm a Simple Bean"> </bean> </beans> 运行它:
[java] view plaincopyprint? 01.public class App 02.{ 03. public static void main( String[] args ) 04. { 05. ConfigurableApplicationContext context = 06. new ClassPathXmlApplicationContext(new String[] {"SpringConfig.xml"}); 07. 08. SimpleBean simple = (SimpleBean )context.getBean("simple"); 09. 10. System.out.println(simple.getName()); 11. 上一页 [1] [2] [3] [4] [5] 下一页
|