如何延迟加载 Spring Security? [英] How do I lazy load Spring Security?

查看:45
本文介绍了如何延迟加载 Spring Security?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在需要之前不实例化 Spring Security?

How do I not instantiate Spring Security until I need to?

我使用的是 Google App Engine,因此我的网络应用程序的启动时间很重要.有时,当用户请求一个页面时,他们必须等待我的 Web 应用程序实例化的整个时间才能获得响应(这称为加载请求).

I'm using Google App Engine so the startup time of my web app is important. Sometimes when a user requests a page, they must wait the whole time for my web app instantiate before getting a response (this is called a loading request).

我的应用程序的某些页面不需要身份验证.对于这些页面,如果请求是加载请求,我不希望用户必须额外等待大约 1.5 秒的时间让 Spring Security 实例化.

Certain pages of my app require no authentication. For these pages, if the request is a loading request, I don't want the user to have to wait the extra ~1.5 seconds for Spring Security to instantiate.

我已经想出了如何延迟加载我的应用程序的所有其他组件,Spring Security 是唯一一个我不知道如何加载的组件.有人有想法吗?

I've already figured out how to lazy load all of the other components of my app, Spring Security is the only one I don't know how. Anyone have an idea?

如果有人知道如何从代码而不是使用 applicationContext-security.xml 实例化 Spring Security,那么我想我可以弄清楚如何延迟加载它.

If anyone knows how to instantiate Spring Security from code instead of using applicationContext-security.xml, then I think I could figure out how to lazy load it.

推荐答案

好吧,我终于想通了.我必须将 org.springframework.web.context.ContextLoaderListenerorg.springframework.web.filter.DelegatingFilterProxy 子类化,以便在我对它们调用 activate 方法之前不做任何事情.

Well, I finally figured it out. I had to subclass org.springframework.web.context.ContextLoaderListener and org.springframework.web.filter.DelegatingFilterProxy to not do anything until I call an activate method on them.

这篇关于如何延迟加载 Spring Security?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆