3

我正在尝试使用 Spring Security,但我发现的所有教程都使用 Spring 框架进行 Web 应用程序:

所以我的问题是:

是否可以在不使用 Spring Framework 的情况下在简单的 Java Web 应用程序中使用 Spring Security,或者它们是否链接在一起?

更新

好吧,事实上,我已经使用 JPA 制作了一个简单的 Java Web 应用程序 - JSP on netbeans。所以现在我决定增加一些安全性。经过一番搜索,我找到了 Shiro、Spring Security 和 JAAS。所以如果我使用 maven,我可以下载 Spring Security 依赖项而不使用 Spring 框架,对吗?

更新 2

这是 XML 文件:

    <?xml version="1.0" encoding="UTF-8"?>

    <web-app xmlns="http://java.sun.com/xml/ns/javaee"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
            version="3.0">
        <session-config>
            <session-timeout>
                30
            </session-timeout>
        </session-config>

            <listener>
                <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
            </listener>

            <context-param>
                <param-name>contextConfigLocation</param-name>
                <param-value>
                    /WEB-INF/MyDispatcherServlet-servlet.xml
                </param-value>
            </context-param>

            <servlet>
                <servlet-name>MyDispatcherServlet</servlet-name>
                <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            </servlet>

            <servlet-mapping>
                <servlet-name>MyDispatcherServlet</servlet-name>
                <url-pattern>*.go</url-pattern>
            </servlet-mapping>

            <filter>
                <filter-name>springSecurityFilterChain</filter-name>
                <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
            </filter>

            <filter-mapping>
                <filter-name>springSecurityFilterChain</filter-name>
                <url-pattern>/*</url-pattern>
            </filter-mapping>

    </web-app>

这是我运行应用程序时的服务器日志错误:

        GRAVE: Class [ Lorg/apache/commons/logging/Log; ] not found. Error while loading [ class org.springframework.security.access.annotation.Jsr250MethodSecurityMetadataSource ]
        ATTENTION: Error in annotation processing: java.lang.NoClassDefFoundError: Lorg/apache/commons/logging/Log;
        GRAVE: Class [ Lorg/apache/commons/logging/Log; ] not found. Error while loading [ class org.springframework.security.access.annotation.Jsr250MethodSecurityMetadataSource ]
        ATTENTION: Error in annotation processing: java.lang.NoClassDefFoundError: Lorg/apache/commons/logging/Log;
        GRAVE: Class [ Lorg/apache/commons/logging/Log; ] not found. Error while loading [ class org.springframework.remoting.jaxws.SimpleHttpServerJaxWsServiceExporter ]
        ATTENTION: Error in annotation processing: java.lang.NoClassDefFoundError: Lorg/apache/commons/logging/Log;
        GRAVE: PWC1306: Startup of context /SpringTestApp_mvn5 failed due to previous errors
        GRAVE: PWC1305: Exception during cleanup after start failed
        org.apache.catalina.LifecycleException: PWC2769: Manager has not yet been started
                at org.apache.catalina.session.StandardManager.stop(StandardManager.java:892)
                at org.apache.catalina.core.StandardContext.stop(StandardContext.java:5456)
                at com.sun.enterprise.web.WebModule.stop(WebModule.java:530)
                at org.apache.catalina.core.StandardContext.start(StandardContext.java:5284)
                at com.sun.enterprise.web.WebModule.start(WebModule.java:499)
                at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:928)
                at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:912)
                at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:694)
                at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1947)
                at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1619)
                at com.sun.enterprise.web.WebApplication.start(WebApplication.java:90)
                at org.glassfish.internal.data.EngineRef.start(EngineRef.java:126)
                at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:241)
                at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:236)
                at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:339)
                at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:183)
                at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:272)
                at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:305)
                at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:320)
                at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1176)
                at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$900(CommandRunnerImpl.java:83)
                at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1235)
                at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1224)
                at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:365)
                at com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:204)
                at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:166)
                at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:100)
                at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:245)
                at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
                at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693)
                at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954)
                at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170)
                at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)
                at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)
                at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)
                at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
                at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
                at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
                at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
                at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
                at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
                at java.lang.Thread.run(Thread.java:619)

        GRAVE: ContainerBase.addChild: start: 
        org.apache.catalina.LifecycleException: java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
                at org.apache.catalina.core.StandardContext.start(StandardContext.java:5289)
                at com.sun.enterprise.web.WebModule.start(WebModule.java:499)
                at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:928)
                at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:912)
                at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:694)
                at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1947)
                at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1619)
                at com.sun.enterprise.web.WebApplication.start(WebApplication.java:90)
                at org.glassfish.internal.data.EngineRef.start(EngineRef.java:126)
                at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:241)
                at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:236)
                at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:339)
                at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:183)
                at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:272)
                at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:305)
                at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:320)
                at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1176)
                at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$900(CommandRunnerImpl.java:83)
                at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1235)
                at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1224)
                at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:365)
                at com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:204)
                at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:166)
                at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:100)
                at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:245)
                at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
                at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693)
                at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954)
                at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170)
                at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)
                at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)
                at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)
                at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
                at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
                at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
                at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
                at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
                at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
                at java.lang.Thread.run(Thread.java:619)
        Caused by: java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
                at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:191)
                at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
                at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:4664)
                at com.sun.enterprise.web.WebModule.contextListenerStart(WebModule.java:535)
                at org.apache.catalina.core.StandardContext.start(StandardContext.java:5266)
                ... 38 more
        Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
                at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
                at java.security.AccessController.doPrivileged(Native Method)
                at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
                at org.glassfish.web.loader.WebappClassLoader.findClass(WebappClassLoader.java:959)
                at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1430)
                at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
                ... 43 more

        ATTENTION: java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
        java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
                at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:932)
                at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:912)
                at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:694)
                at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1947)
                at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1619)
                at com.sun.enterprise.web.WebApplication.start(WebApplication.java:90)
                at org.glassfish.internal.data.EngineRef.start(EngineRef.java:126)
                at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:241)
                at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:236)
                at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:339)
                at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:183)
                at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:272)
                at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:305)
                at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:320)
                at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1176)
                at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$900(CommandRunnerImpl.java:83)
                at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1235)
                at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1224)
                at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:365)
                at com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:204)
                at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:166)
                at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:100)
                at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:245)
                at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
                at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693)
                at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954)
                at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170)
                at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)
                at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)
                at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)
                at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
                at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
                at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
                at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
                at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
                at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
                at java.lang.Thread.run(Thread.java:619)

        GRAVE: Exception while invoking class com.sun.enterprise.web.WebApplication start method
        java.lang.Exception: java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
                at com.sun.enterprise.web.WebApplication.start(WebApplication.java:117)
                at org.glassfish.internal.data.EngineRef.start(EngineRef.java:126)
                at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:241)
                at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:236)
                at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:339)
                at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:183)
                at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:272)
                at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:305)
                at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:320)
                at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1176)
                at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$900(CommandRunnerImpl.java:83)
                at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1235)
                at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1224)
                at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:365)
                at com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:204)
                at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:166)
                at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:100)
                at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:245)
                at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
                at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693)
                at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954)
                at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170)
                at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)
                at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)
                at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)
                at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
                at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
                at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
                at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
                at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
                at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
                at java.lang.Thread.run(Thread.java:619)

        GRAVE: Exception while loading the app
        java.lang.Exception: java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
                at com.sun.enterprise.web.WebApplication.start(WebApplication.java:117)
                at org.glassfish.internal.data.EngineRef.start(EngineRef.java:126)
                at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:241)
                at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:236)
                at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:339)
                at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:183)
                at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:272)
                at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:305)
                at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:320)
                at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1176)
                at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$900(CommandRunnerImpl.java:83)
                at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1235)
                at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1224)
                at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:365)
                at com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:204)
                at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:166)
                at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:100)
                at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:245)
                at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
                at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693)
                at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954)
                at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170)
                at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)
                at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)
                at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)
                at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
                at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
                at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
                at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
                at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
                at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
                at java.lang.Thread.run(Thread.java:619)
4

5 回答 5

4

我认为这是不可能的,因为 Spring Security 是建立在 Spring 框架之上的。

虽然您可以将 maven 配置为仅下载 Spring Security 依赖项,但由于 Spring Security 的源代码使用了 Spring 框架中的许多类和功能,因此您的项目将不会成功执行并且NoClassDefFoundError有时会抛出异常。

如果你想使用不依赖spring框架的安全框架,请查看Apache Shiro

于 2013-05-26T16:49:31.440 回答
2

在您的应用程序中包含spring的内容包括其中的 spring 安全实现(它最终是一个 java 类实现)。我认为spring在您的应用程序中不包含框架没有好处,而只包含它的安全实现。

于 2013-05-26T16:34:48.907 回答
1

这是不可能的,Spring Security 需要 Spring Framework 来实例化类以提供其特性。

您可以在此处查看手册中 Spring Security 的依赖项。

Spring Security 所需的 Spring 版本发布在Spring Security 网站上

  • Spring Security 3.2.0.M1 是最新的开发版本(需要 Java 1.5+ 和 Spring 3.2.0+)
  • Spring Security 3.1.4.RELEASE 是最新的生产版本(需要 Java 1.5+ 和 Spring 3.0.7+)
  • Spring Security 3.0.8.RELEASE 是之前的生产版本(需要 Java 1.5+ 和 Spring 3.0.6+)

事实上 Spring Security POM 模块显示了一些依赖关系:

于 2013-05-26T16:46:15.060 回答
1

您可以为此使用 maven-aspectj-plugin。当一个类使用@Configurable注解时,这个插件可以在编译时注入依赖。@Configurable是一个Spring注解,它允许将依赖注入到Spring外部实例化的对象中。您不必将所有项目都基于 spring

于 2013-07-15T09:00:59.283 回答
0

在没有 Spring Boot 的情况下使用 Spring Security 时,首选方法是利用 Spring Security 的 BOM 来确保在整个项目中使用一致的 Spring Security 版本。参考这里。您可以使用SecurityWebApplicationInitializer初始化您的应用程序。

于 2018-11-02T07:46:21.517 回答