Announcement Announcement Module
Collapse
No announcement yet.
Spring2.5 + glassfish + jndi remote + Controller Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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 {
    @EJB(name="beanName")
    private Bean aBean;
    ....


    The bean is on a remote server. In sun-web.xml (glassfish specific):
    <sun-web-app>
    <ejb-ref>
    <ejb-ref-name>beanName</ejb-ref-name>
    <jndi-name>
    corbaname:iiop:servername:33700#com.myapp.Bean
    </jndi-name>
    </ejb-ref>
    </sun-web-app>


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

    @EJB(name="beanName")
    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:
    Code:
      <bean id="jndiFactory" class="org.springframework.jndi.support.SimpleJndiBeanFactory">
        <property name="resourceRef" value="false" />
      </bean>
    
      <bean class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor">
        <property name="alwaysUseJndiLookup" value="true" />
        <property name="jndiFactory" ref="jndiFactory" />
      </bean>
    
      <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.

    Comment

    Working...
    X