Results 1 to 2 of 2

Thread: Spring @Autowired annotation in EJB

  1. #1
    Join Date
    Aug 2009
    Posts
    3

    Question Spring @Autowired annotation in EJB

    Hi All,

    I am using, EJB2.1, Spring 2.5.5, Weblogic server 10.0 and the IDE is Weblogic studio 10.2.

    I have written a Stateless Session bean and trying to invoke that from a TestServlet class through JNDI. I am able to invoke the EJB method from servlet. It works fine.

    The next step is to invoke the methods of other layer in EJB through Spring IoC (Dependency Injection). To achieve this, I am using @Autowired annotations. I am not able to get the bean instantiation into the local variable of EJB.

    I am able to call the methods through the following piece of code (This doesnt use annotations).
    Code:
    BeanFactoryLocator locator = ContextSingletonBeanFactoryLocator
    			.getInstance("beanRefContext.xml");
    
    	BeanFactoryReference bfr = locator.useBeanFactory("businessBeanFactory");
    
    	BeanFactory factory = bfr.getFactory();
    
    	private IGeoCodeSearchEngine geoCodeSearchEngine = (IGeoCodeSearchEngine) factory
    			.getBean("geoCodeSearchEngine");
    I am getting the null pointer exception when i try to invoke the method as follows:

    Code:
    @Interceptors(TaxCalculatorAutowireInterceptor.class)
    public class TaxCalculator extends GenericSessionBean implements SessionBean {
    	private static final long serialVersionUID = 1L;
    
    	 @Autowired
    	 private IGeoCodeSearchEngine geoCodeSearchEngine;
    
             geoCodeSearchEngine.searchGeoCode();
    I am not able to find where i am struck.
    Please help me in this....

  2. #2
    Join Date
    Jul 2009
    Location
    Bogota, Colombia
    Posts
    6

    Default

    if you're using EJB2.1 you can't use the @Interceptors annotations, that's intended to be used with EJB3. Anyway you can define your interceptors on the ejb-jar.xml file, you can find multiple examples of this on the web.

    Take a look to this link, it shows how to define the interceptor on the default .xml file, just don't use the @Interceptors annotation, is ok to use the @Autowired but not the @Interceptors:

    http://www.adam-bien.com/roller/abie...3_for_absolute

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •