美文网首页
Tomcat Name [UserDatabase] is no

Tomcat Name [UserDatabase] is no

作者: 风吟空城 | 来源:发表于2018-12-25 11:32 被阅读0次

    起因

    在tomcat启动时,总会报Name [UserDatabase] is not bound in this Context这一异常,但是也不会影响tomcat中程序的正常运行,但总是报异常不解决看着也难受,在这里记录下解决的过程。

    异常代码

    Caused by: org.apache.catalina.LifecycleException: No UserDatabase component found under key [UserDatabase]
        at org.apache.catalina.realm.UserDatabaseRealm.startInternal(UserDatabaseRealm.java:239)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        ... 17 more
    

    思路

    从异常代码中可以看出,应该是缺少UserDatabase这一组件(配置)。以此为出发点,联想到Tomcat的Server.xml中有UserDatabase这一配置项。所以开始检查conf/server.xml文件。

    通过检查conf/server.xml文件,找到了UserDatabase的配置项及其引用,代码如下:

    配置项

      <!-- Global JNDI resources
           Documentation at /docs/jndi-resources-howto.html
      -->
      <GlobalNamingResources>
        <!-- Editable user database that can also be used by
             UserDatabaseRealm to authenticate users
        -->
        <Resource name="UserDatabase" auth="Container"
                  type="org.apache.catalina.UserDatabase"
                  description="User database that can be updated and saved"
                  factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
                  pathname="conf/tomcat-users.xml" />
      </GlobalNamingResources>
    

    引用

          <!-- Use the LockOutRealm to prevent attempts to guess user passwords
               via a brute-force attack -->
          <Realm className="org.apache.catalina.realm.LockOutRealm">
            <!-- This Realm uses the UserDatabase configured in the global JNDI
                 resources under the key "UserDatabase".  Any edits
                 that are performed against this UserDatabase are immediately
                 available for use by the Realm.  -->
            <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
                   resourceName="UserDatabase"/>
          </Realm>
    

    解决办法

    1. 首先查看是否正常引用UserDatabase
    2. 如果引用了UserDatabase,再查看server.xml文件中是否存在其配置项;

    相关文章

      网友评论

          本文标题:Tomcat Name [UserDatabase] is no

          本文链接:https://www.haomeiwen.com/subject/qngxlqtx.html