</bean>
<context:annotation-config/>
<jpa:repositories base-package="com.apress.prospring3.ch16.repository"
entity-manager-factory-ref="emf"
transaction-manager-ref="transactionManager"/>
</beans>
For details on the definition of each bean, please refer to Chapter 10. Then, we need to import the
configuration into Spring's root WebApplicationContext. For a Spring MVC template project, the file is
located at /src/main/webapp/WEB-INF/spring/root-context.xml. Listing 16-8 shows the revised file.
Listing 16-8. The root-context.xml File
<?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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<import resource="classpath:datasource-tx-jpa.xml" />
<context:component-scan
base-package="com.apress.prospring3.ch16.service.jpa" />
</beans>
First the context namespace is added to the configuration file. Then, the file datasource-tx-jpa.xml
was imported into the WebApplicationContext, and finally, we instruct Spring to scan for the specified
package for Spring beans.
Now, the service layer is completed and ready to be exposed and used by remote clients.
Using the Spring HTTP Invoker
If the application you are going to communicate with is also Spring-powered, using the Spring HTTP
invoker is a good choice. It provides an extremely simple way to expose the services within the Spring
WebApplicationContext to remote clients also using the Spring HTTP invoker to invoke the service. The
procedures for exposing and accessing the service are elaborated in the following sections.
Exposing the Service
To expose the service, in the root-context.xml configuration file, add the bean definition in Listing 16-9.
Listing 16-9. Bean for Exposing Contact Service Using HTTP Invoker
<bean name="contactExporter"
class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter">
<property name="service" ref="contactService" />
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home