按照Spring开发指南的步骤走,卡在了4红色部分
1.[Action.java]
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->1
package com.xc.sp;
2
3
public interface Action
{
4
5
public String execute(String str);
6
}
package com.xc.sp;2

3

public interface Action
{4

5
public String execute(String str);6
}
2.[UpperAction.java]
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--> 1
package com.xc.sp;2

3
import com.xc.sp.Action;4

5

public class UpperAction implements Action
{6
7
private String message;8
9

public String getMessage()
{10
return message;11
}12
13

public void setMessage(String string)
{14
message = string;15
}16
17

public String execute(String str)
{18
return (getMessage() + str).toUpperCase();19
}20
}21

22
3.[testsp.java]
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--> 1
package Test;2

3
import org.springframework.context.ApplicationContext;4
import org.springframework.context.support.FileSystemXmlApplicationContext;5

6
import com.xc.sp.Action;7

8

public class testsp
{9

10

/** *//**11
* @param args12
*/13

public static void main(String[] args)
{14
// TODO Auto-generated method stub 15
ApplicationContext ctx = new FileSystemXmlApplicationContext("bean.xml");16
Action action = (Action) ctx.getBean("TheAction");17
System.out.println(action.execute("Rod Johnson"));18
}19

20
}21

22
4.[bean.xml]注意要有红色这部分
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--> 1
<?xml version="1.0" encoding="UTF-8"?>2
<!DOCTYPE beans PUBLIC "-//SPRING/DTD BEAN/EN" "http://www.springframework.org/dtd/spring-beans.dtd">3
<beans> 4
<description>Spring Quick Start</description>5
<bean id="TheAction" class="com.xc.sp.UpperAction">6
<property name="message">7
<value>HeLLo</value>8
</property>9
</bean>10
</beans>11

12
本文介绍了一个简单的Spring框架应用实例,包括定义接口Action及其实现类UpperAction,并通过testsp类进行测试,展示了如何配置bean.xml来注入依赖并调用方法。

被折叠的 条评论
为什么被折叠?



