gpt4 book ai didi

guice - 使用 guice servlet 扩展时,是否可以对 servlet 破坏使用react?

转载 作者:行者123 更新时间:2023-12-04 06:09:44 29 4
gpt4 key购买 nike

删除 guice servlet 后,我​​需要进行一些清理。使用 guice servlet 时是否可以 Hook 到 servlet 破坏?我需要使用喷油器进行清理工作。

我可以覆盖 contextDestroyed GuiceServletContextListener 中的方法,但是我如何访问喷油器?

有没有更好的方法来应对 servlet 破坏?

最佳答案

I can override the contextDestroyed method in GuiceServletContextListener, but then how do I get access to the injector?



你可以这样做:
public class MyGuiceServletConfig extends GuiceServletContextListener {
private final Injector injector = Guice.createInjector(new ServletModule());

@Override
protected Injector getInjector() {
return injector;
}

@Override
public void contextDestroyed(ServletContextEvent servletContextEvent) {
injector.getInstance(MyCleanUp.class);
}
}

或者像这样:
public class MyGuiceServletConfig extends GuiceServletContextListener {

@Override
protected Injector getInjector() {
return Guice.createInjector(new ServletModule());
}

@Override
public void contextDestroyed(ServletContextEvent sce) {
Injector injector = (Injector) sce.getServletContext()
.getAttribute(Injector.class.getName());
}
}

关于guice - 使用 guice servlet 扩展时,是否可以对 servlet 破坏使用react?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7915155/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com