| return message; } public void setMessage(String string) { message = string; } public String execute(String str) { return (getMessage() + str).toUpperCase(); } } 配置文件bean.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <description>Spring Quick Start</description> <bean id="TheAction" class="beantest.LowerAction"> <property name="message"> <value>HeLLo </value> </property> </bean> </beans> 使用 ApplicationContext 来操作他们。 public static void main(String[] args) { System.out.println("Hello!"); try { ApplicationContext ctx = new FileSystemXmlApplicationContext("bean.xml"); Action action = (Action) ctx.getBean("TheAction"); System.out.println(action.execute("Rod Johnson")); } catch(Exception e) { 上一页 [1] [2] [3] [4] 下一页 |