Announcement Announcement Module
No announcement yet.
Spring2.5 + glassfish + jndi remote + Controller Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring2.5 + glassfish + jndi remote + Controller

    I have a plain http servlet running under glassfish. It contains an EJB reference:

    public class TestServlet extends HttpServlet {
    private Bean aBean;

    The bean is on a remote server. In sun-web.xml (glassfish specific):

    Deploying works fine. Now I try and get Spring controllers into the act:
    public class HomeController {

    private DSDocDAO limsRepository;

    My problem is I don't know where to wire the remote slsb into the Spring context.
    Anyone using Spring and Glassfish out there?

  • #2
    Here's how I got it to work (Spring 2.5.2).

    In myapp-servlet.xml, I have something like:
      <bean id="jndiFactory" class="">
        <property name="resourceRef" value="false" />
      <bean class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor">
        <property name="alwaysUseJndiLookup" value="true" />
        <property name="jndiFactory" ref="jndiFactory" />
      <bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor" />
      <context:component-scan base-package="com.myapp.controllers" annotation-config="false" />
    This basically sets up annotation-based component scanning and dependency injection using a custom JndiFactory that's configured not to prepend lookups with java:comp/env.

    Spring does pretty much does everything else: upon seeing HomeController annotated with @Controller, it scans it and sees limsRepository annotated with @EJB, looks up "beanName" in JNDI, and so on and so forth.

    Had to wrestle with various naming problems (I use @EJB(mappedName = "..."), YMMV) depending on the application server, but this has worked for me on both Glassfish v2 and JBoss 4.2.