java tomcat数据库配置

s4n0splo  于 2021-10-10  发布在  Java
关注(0)|答案(0)|浏览(191)

我遇到了一个异常:org.apache.catalina.lifecycleexception:key[jdbc/spp]下找不到userdatabase组件。根据互联网上的一些教程,配置对我来说似乎很好。这是我的档案:
server.xml

<?xml version="1.0" encoding="UTF-8"?>
  <Listener SSLEngine="on" className="org.apache.catalina.core.AprLifecycleListener"/>
  <!-- Prevent memory leaks due to use of particular java/javax APIs-->
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/>
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener"/>

  <GlobalNamingResources>
    <Resource auth="Container" description="" driverClassName="org.postgresql.Driver" initialSize="5" maxActive="120" maxIdle="5" maxWait="5000" name="jdbc/spp" password="postgres" poolPreparedStatements="true" type="javax.sql.DataSource" url="jdbc:postgresql://localhost:5432/spp" username="postgres" validationQuery="select 1"/>
  </GlobalNamingResources>

  <Service name="Catalina">
    <Connector connectionTimeout="20000" port="8081" protocol="HTTP/1.1" redirectPort="8443"/>
    <Engine defaultHost="localhost" name="Catalina">

      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="jdbc/spp"/>
      </Realm>

      <Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%h %l %u %t &quot;%r&quot; %s %b" prefix="localhost_access_log" suffix=".txt"/>

      <Context docBase="spp" path="/spp" reloadable="true" source="org.eclipse.jst.jee.server:spp" />
      </Host>
    </Engine>
  </Service>
</Server>

context.xml

<?xml version="1.0" encoding="UTF-8"?>
<Context>
    <WatchedResource>WEB-INF/web.xml</WatchedResource>
    <WatchedResource>WEB-INF/tomcat-web.xml</WatchedResource>
    <WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>

    <ResourceLink name="jdbc/spp"
             global="jdbc/spp"
              type="javax.sql.DataSource" >
    </ResourceLink>
</Context>

tomcat-users.xml

<?xml version="1.0" encoding="UTF-8"?>
<tomcat-users version="1.0" xmlns="http://tomcat.apache.org/xml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://tomcat.apache.org/xml tomcat-users.xsd">

</tomcat-users>

在我的属性文件中,我有app.datasource=java:comp/env/jdbc/spp。您能看到任何可能导致该异常的错误吗?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题