Skip to content

Instantly share code, notes, and snippets.

@schakko
Created October 11, 2013 05:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schakko/6930130 to your computer and use it in GitHub Desktop.
Save schakko/6930130 to your computer and use it in GitHub Desktop.
Interceptor for use @Autowired in EJBs with global Spring application context
import javax.ejb.EJB;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor;
import de.ckl.ejb.SpringContextBean;
/**
* {@link SpringContextInterceptor} can be used for autowiring Spring beans
* inside EJBs. Unlike {@link SpringBeanAutowiringInterceptor} the
* {@link SpringContextInterceptor} uses the application wide shared Spring
* application context from {@link SpringContextBean}.
*
* @author ckl
*/
public class SpringContextInterceptor extends SpringBeanAutowiringInterceptor {
@EJB
SpringContextBean springContextBean;
protected BeanFactory getBeanFactory(Object target) {
return springContextBean.getApplicationContext()
.getAutowireCapableBeanFactory();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment