Guest User

Access Spring beans from a servlet in JBoss

a guest
Feb 26th, 2012
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  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");
Add Comment
Please, Sign In to add comment