Java Reference
In-Depth Information
<bean id="frontDesk"
class="com.apress.springenterpriserecipes.post.FrontDeskImpl">
<property name="postageService" ref="postageService" />
</bean>
</beans>
You have to configure the JNDI details for this EJB proxy in the jndiEnvironment and jndiName
properties. The most important is to specify the business interface for this proxy to implement. The
calls to methods declared in this interface will be translated into remote method calls to the remote EJB
component. You can inject this proxy into FrontDeskImpl in the same way as a normal bean.
EJB proxies can also be defined using the <jee:remote-slsb> and <jee:local-slsb> elements in the
jee schema. You must add the jee schema definition to the <beans> root element beforehand.
<beans xmlns=" http://www.springframework.org/schema/beans"
xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance"
xmlns:jee=" http://www.springframework.org/schema/jee"
xsi:schemaLocation=" http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-3.0.xsd">
<jee:remote-slsb id="postageService"
jndi-name="PostageServiceRemoteHome"
business-interface="com.apress.springenterpriserecipes.post.PostageService">
<jee:environment>
java.naming.factory.initial=
org.apache.openejb.client.RemoteInitialContextFactory
java.naming.provider.url= ejbd://localhost:4201
</jee:environment>
</jee:remote-slsb>
...
</bean>
To access the EJB from a client, your code looks like almost any example demonstrating accessing
beans from a Spring context. It describes the instantiation of a Spring ApplicationContext and the use of
a bean that's interface-compatible with your service's POJO interface.
import org.springframework.context.ApplicationContext;
public class FrontDeskMain {
public static void main(String[] args) {
ApplicationContext context =
new ClassPathXmlApplicationContext("beans-front.xml");
FrontDesk frontDesk = (FrontDesk) context.getBean("frontDesk");
double postage = frontDesk.calculatePostage("US", 1.5);
System.out.println(postage);
}
}
Search WWH ::




Custom Search