Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Access Spring beans from a servlet in JBoss

By: a guest on Feb 26th, 2012  |  syntax: None  |  size: 0.77 KB  |  views: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <bean class="org.springframework.web.context.support.ServletContextAttributeExporter">
  2.   <property name="attributes">
  3.     <map>
  4.       <entry key="jobbie" value-ref="springifiedJobbie"/>
  5.     </map>
  6.   </property>
  7. </bean>
  8.        
  9. SpringifiedJobbie jobbie = (SpringifiedJobbie) getServletContext().getAttribute("jobbie");
  10.        
  11. public class MyServlet extends HttpServlet {
  12.  
  13.   @Autowired
  14.   private MyService myService;
  15.  
  16.   public void init(ServletConfig config) {
  17.     super.init(config);
  18.     SpringBeanAutowiringSupport.processInjectionBasedOnServletContext(this,
  19.       config.getServletContext());
  20.   }
  21. }
  22.        
  23. WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
  24. SpringifiedJobbie jobbie = (SpringifiedJobbie)context.getBean("springifiedJobbie");