?????????WEB-INF?μ?web.xml??????SpringMVC????????
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<servlet>
<servlet-name>springMvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springMvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
?????塢??applicationContext.xml????????????????bean???
????<bean id="furitService" class="service.impl.FruitServiceImpl"></bean>
????<bean id="FuritService"
????class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter"
????p:serviceInterface="service.FruitService" p:service-ref="furitService" />
??????????WEB-INF?′???springMvc-servlet.xml???????????urlMapping
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="urlMapping"
class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/fruitService">FuritService</prop>
</props>
</property>
</bean>
</beans>
?????????applicationContext.xml??д????????????÷????bean???
????<bean id="getFruitService"
????class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean"
????p:serviceInterface="service.FruitService"
????p:serviceUrl="http://localhost:8080/SpringHttpInvoker/fruitService" />
?????????д???????
package test;
import java.util.List;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import entity.Fruit;
import service.FruitService;
public class Test {
public static void main(String[] args) {
ApplicationContext ctx = new ClassPathXmlApplicationContext(
"applicationContext.xml");
FruitService fruitService = (FruitService) ctx
.getBean("getFruitService");
List<Fruit> fruitList = fruitService.getFruitList();
for (Fruit fruit : fruitList) {
System.out.println(fruit.getColor() + "??" + fruit.getName());
}
}
}
?????????????Tomcat??????Tomcat?????????в??????