我想直接从java代码中使用没有spring应用程序上下文(或spring容器)的spring-security web过滤器。
这个是可能的吗?我可以直接调用不同的spring生命周期方法吗?如果可以,有没有这样做的示例(需要关注哪些不同的接口以及它们的顺序)?
发布于 2011-07-27 14:46:14
我认为这是可能的,但不值得。
Spring是一个复杂的框架,它隔离了您配置Java应用程序的负担。为什么要使用没有Spring的Spring?
关于你的问题,以前的Spring安全,Acegi,声称可以在没有Spring的情况下使用。
所以你可以试一下,但是你的主要问题是在服务器启动时加载整个应用程序。您需要复制包含ContextLoaderListener的功能。
尝试创建自己的监听器,而不是
    <!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>然后,按照Simeon所说的那样,为您的应用程序配置主servlet (因为我假设您不想使用Spring MVC)和安全过滤器。
祝你好运。
或者,您可以尝试Apache SHIRO。
发布于 2011-07-26 21:00:51
我想在没有spring应用程序上下文的情况下使用spring安全web过滤器
你不能。
因为当您在web.xml中定义筛选器链代理时
<filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>DelegatingFilterProxy实际上希望在其中找到您的contextConfigLocation和有效的配置文件:
<context-param>
    <param-name>contextConfigLocation</param-name>
    <!-- This must be valid otherwise your .war deployment will fail -->
    <param-value>WEB-INF/spring-contexts/spring-contexts.xml</param-value>
</context-param>https://stackoverflow.com/questions/6829256
复制相似问题