java-为什么需要在Server.xml中而不是web.xml中设置领域设置
作者:互联网
我正在研究Java应用程序一段时间.我主要在.NET平台上工作.尽管我觉得这两个平台之间有很多共同的概念,但是在很少的地方可以找到一些与配置有关的问题.
我正在研究身份验证和授权,并认为可以获得与JAVA中的.NET成员资格API类似的东西.我最近得到的是使用j_security_check.我还了解了JAAS,但认为对我来说太深了.
我已经在数据库中创建了用户表和角色表,现在我必须在某处指定JDBC Realm设置.我正在使用Tomcat 7.0.在大多数地方,都提到我需要在server.xml中指定领域设置,但这不适用于该服务器上部署的所有Web应用程序,因为它将成为服务器级配置?
在一个网站上,我什至看到开发人员提到了context.xml,但是再也看不到一个标准文档,该文档提到了使用此XML文件设置JDBC领域
在.NET中,我们始终将成员资格设置放在web.config级别,而不是Machine.config.
对此完全困惑.寻找一些光.
解决方法:
Why is Realm setting required in Server.xml and not web.xml
这是不正确的,您也可以在webapp中定义它,但是只能在servlet容器特定的配置文件中定义,例如对于Tomcat,则是/META-INF/context.xml.无法在/WEB-INF/web.xml中定义它,因为它特定于标准Servlet API,而不是servletcontainer实现.
But wouldn’t that apply to all web application deployed on that server since it would become a server level configuration ?.
没错如果您无法控制服务器或不想通过其他Web应用程序发布领域,则不建议这样做.
On a site I even saw a developer mentioning about context.xml but again can’t see a standard document that mention about using this XML file for setting JDBC realm
您可以在webapp的/META-INF/context.xml中指定它.另请参见Tomcat’s own documentation on the <Context>
element:
Defining a context
It is NOT recommended to place
<Context>
elements directly in theserver.xml
file. This is because it makes modifying the Context configuration more invasive since the mainconf/server.xml
file cannot be reloaded without restarting Tomcat.Individual Context elements may be explicitly defined:
In an individual file at
/META-INF/context.xml
inside the application files. Optionally (based on the Host’s copyXML attribute) this may be copied to$CATALINA_BASE/conf/[enginename]/[hostname]/
and renamed to application’s base file name plus a “.xml” extension.In individual files (with a “.xml” extension) in the
$CATALINA_BASE/conf/[enginename]/[hostname]/
directory. The context path and version will be derived from the base name of the file (the file name less the .xml extension). This file will always take precedence over any context.xml file packaged in the web application’s META-INF directory.Inside a 07001 element in the main
conf/server.xml
.
(重点不是我的,它已经在Tomcat的文档中这样)
标签:j-security-check,tomcat,jdbcrealm,java,java-ee 来源: https://codeday.me/bug/20191202/2085684.html