<security:http .../> 必须在 configContextLocation 的配置。它无法声明 ...-servlet.xml ,因为在请求处理期间,它应该在识别目标servlet之前可用。
<security:http .../>
configContextLocation
...-servlet.xml
<security:global-method-security .../> (据我所知)注册一个bean后处理器,它应用于声明它的上下文(即在 configContextLocation 的xml,它适用于在那里声明的bean,但不适用于声明的bean ...-servlet.xml )
<security:global-method-security .../>
您应该能够将两者都放在一个XML中,只需确保正确声明了架构。我在Spring 2.5和Spring 3中都在同一个文件中使用过它们。
当你说它在两个文件中都不起作用时,我认为你的意思是没有安全性应用于你的方法调用? 如果是这种情况,请确保您的应用程序通过spring加载并使用这些类,否则将不会应用安全性。例如。如果你访问一个类:
MyClass instance = new MyClass(); instance.doSomething();
如果doSomething()使用安全注释进行注释,则不会对该注释做出任何反应。如果您从servlet中使用它而不是通过弹簧等注入它,也是如此。
如果这没有帮助,你能澄清一下你的问题吗?
在后一种情况下, <security:http /> element可能不是定义的xml架构的一部分。所以,它可能会得到例外。顺便问一下,有什么例外?
<security:http />
在前一种情况下,它没有用。可能是因为Spring在DispatcherServlet加载的xml配置中查找此元素,否则忽略它。我也不确定,但似乎是这样。 :)
看这个 春天论坛帖子 。他们正在讨论相同的问题。把它们加起来, 的 “从主上下文中看不到* -servlet.xml bean” 强> 。
在处女座中,主要配置由定义 org.eclipse.virgo.web.dm.ServerOsgiBundleXmlWebApplicationContext 在web.xml中,所以我不得不将安全配置导入applicationContext.xml而不是* -servlet.xml <import resource="applicationContext-security.xml"/> 修好了 No bean named 'springSecurityFilterChain' is defined
org.eclipse.virgo.web.dm.ServerOsgiBundleXmlWebApplicationContext
<import resource="applicationContext-security.xml"/>
No bean named 'springSecurityFilterChain' is defined