我正在使用Guice连接Jetty服务器,我想通过Apache Shiro添加一些安全性。
似乎 Shiro 需要配置一个ServletContext,但问题是我在配置时没有 ServletContext(例如在文档所述的ServletModule中)。ServletContext在GuiceServletContextListener中可用,但此时,我的注入器已经创建,所以安装Shiro模块为时已晚。
我尝试通过Guice提供程序(Provider<ServletContext> )将ServletContext提供给Shiro ,但仍然没有成功。我认为这个提供者将在创建后为 ServletContext 提供服务。这也给出了一个警告:
"com.google.inject.servlet.InternalServletModule$BackwardsCompatibleServletContextProvider get
WARNING: You are attempting to use a deprecated API (specifically, attempting to @Inject ServletContext inside an eagerly created singleton. While we allow this for backwards compatibility, be warned that this MAY have unexpected behavior if you have more than one injector (with ServletModule) running in the same JVM."
创建注入器后如何安装 Shiro Web 模块?