Created
May 19, 2014 14:09
-
-
Save rponte/e082815d9a44154351ab to your computer and use it in GitHub Desktop.
Accessing Spring bean from Servlet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AppServlet extends HttpServlet { | |
@Autowired | |
ApplicationContext applicationContext; | |
@Override | |
public void init(ServletConfig arg0) throws ServletException { | |
WebApplicationContextUtils.getWebApplicationContext(arg0.getServletContext()) | |
.getAutowireCapableBeanFactory().autowireBean(this); | |
} | |
@Override | |
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { | |
PrintWriter out = resp.getWriter(); | |
out.println("execução iniciada em: " + new Date()); | |
GerenciadorTasks gt = (GerenciadorTasks) this.applicationContext.getBean(SpringNameBeans.GERENCIADOR_TASKS); | |
gt.init(); | |
out.println("execução terminada em: " + new Date()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://stackoverflow.com/questions/467235/access-spring-beans-from-a-servlet-in-jboss
http://stackoverflow.com/questions/13625563/why-my-spring-application-context-reloads-every-time-a-servlet-is-accessed