实现类一:HelloWorld1.java
public class HelloWorld1 implements IHelloWorld
{
public HelloWorld1()
{
super();
}
public String sayHelloWorld()
{
return "Hello World HelloWorld1";
}
}
实现类二:HelloWorld2.java
public class HelloWorld2 implements IHelloWorld
{
public HelloWorld2()
{
super();
}
public String sayHelloWorld()
{
return "Hello World HelloWorld2";
}
}
根据常用的三层与Spring的最佳实践,将配置文件分成了四个
beanRefFactory.xml负责总装,由SingletonBeanFactoryLocator来装入
通过ClassPathXmlApplicationContext来把其它三个模块的文件引入
beanRefDataAccess.xml负责DAO,与数据库相关的bean都定义在这里
beanRefService.xml负责Service层的bean定义
beanRefMVC.xml负责Spring MVC方面相关的bean定义等等
以下配置文件的bean定义为演示所用,各自的内容如下:
beanRefFactory.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="beanFactory" class="org.springframework.context.support.ClassPathXmlApplicationContext">
<constructor-arg>
<list>
<value>beanRefDataAccess.xml</value>
<value>beanRefService.xml</value>
<value>beanRefMVC.xml</value>
</list>
</constructor-arg>
</bean>
</beans>
beanRefDataAccess.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="helloWorldDAO1" class="HelloWorld1"/>
<bean id="helloWorldDAO2" class="HelloWorld2"/>
</beans>
Eclipse插件之Spring IDE(6)
时间:2010-12-31 BEA 俞黎敏
beanRefService.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="helloWorld1" class="HelloWorld1"/>
<bean id="helloWorld2" class="HelloWorld2"/>
<bean id="springDemoConstructor" class="SpringDemoConstructor">
<constructor-arg>
<value>Spring IDE Constructor</value>
</constructor-arg>
<property name="helloWorld">
<ref bean="helloWorld1"></ref>
</property>
</bean>
<bean id="springDemoSetter" class="SpringDemoSetter">
<property name="hello" value="Spring IDE Setter"/>
<property name="helloWorld">
<ref bean="helloWorld2"></ref>
</property>
</bean>
</beans>
beanRefMVC.xml的内容如下:
<xml version="1.0" encoding="UTF-8">
<!DOCTYPE
|