【问题标题】:Tomcat (TomEE)/7.0.62 (1.7.2) XML Configuration Files best practicesTomcat (TomEE)/7.0.62 (1.7.2) XML 配置文件最佳实践
【发布时间】:2015-06-20 18:49:30
【问题描述】:

我在C:// 中解压缩了一个二进制发行版,但我很难让JDBCJDNI 正常工作...它没有从我的数据库中获取数据,所以我认为我没有合适的文件的配置。

奇怪的是,<c:forEach var="cartItem" items="${cart.items}" varStatus="iter"/> 可以看到数据,但<c:forEach var="product" items="${categoryProducts}" varStatus="iter"/> 没有数据显示

编辑

server.xml: /conf

    <?xml version='1.0' encoding='utf-8'?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<!-- Note:  A "Server" is not itself a "Container", so you may not
     define subcomponents such as "Valves" at this level.
     Documentation at /docs/config/server.html
 -->
<Server port="8005" shutdown="SHUTDOWN">
  <!-- TomEE plugin for Tomcat -->
  <Listener className="org.apache.tomee.catalina.ServerListener"/>
  <Listener className="org.apache.catalina.startup.VersionLoggerListener"/>
  <!-- Security listener. Documentation at /docs/config/listeners.html
  <Listener className="org.apache.catalina.security.SecurityListener" />
  -->
  <!--APR library loader. Documentation at /docs/apr.html -->
  <Listener SSLEngine="on" className="org.apache.catalina.core.AprLifecycleListener"/>
  <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
  <Listener className="org.apache.catalina.core.JasperListener"/>
  <!-- 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"/>

  <!-- 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 auth="Container" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" name="UserDatabase" pathname="conf/tomcat-users.xml" type="org.apache.catalina.UserDatabase"/>
  </GlobalNamingResources>

  <!-- A "Service" is a collection of one or more "Connectors" that share
       a single "Container" Note:  A "Service" is not itself a "Container",
       so you may not define subcomponents such as "Valves" at this level.
       Documentation at /docs/config/service.html
   -->
  <Service name="Catalina">

    <!--The connectors can use a shared executor, you can define one or more named thread pools-->
    <!--
    <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
        maxThreads="150" minSpareThreads="4"/>
    -->


    <!-- A "Connector" represents an endpoint by which requests are received
         and responses are returned. Documentation at :
         Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
         Java AJP  Connector: /docs/config/ajp.html
         APR (HTTP/AJP) Connector: /docs/apr.html
         Define a non-SSL HTTP/1.1 Connector on port 8080
    -->
    <Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1"
               redirectPort="8443"/>
    
    
    <!-- A "Connector" using the shared thread pool-->
    <!--
    <Connector executor="tomcatThreadPool"
               port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    -->
    <!-- Define a SSL HTTP/1.1 Connector on port 8443
         This connector uses the BIO implementation that requires the JSSE
         style configuration. When using the APR/native implementation, the
         OpenSSL style configuration is required as described in the APR/native
         documentation -->
    <!--
    <Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol"
               maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS" xpoweredBy="false" server="Apache TomEE" />
    -->

    <!-- Define an AJP 1.3 Connector on port 8009 -->
    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443"/>


    <!-- An Engine represents the entry point (within Catalina) that processes
         every request.  The Engine implementation for Tomcat stand alone
         analyzes the HTTP headers included with the request, and passes them
         on to the appropriate Host (virtual host).
         Documentation at /docs/config/engine.html -->

    <!-- You should set jvmRoute to support load-balancing via AJP ie :
    <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
    -->
    <Engine defaultHost="localhost" name="Catalina">

      <!--For clustering, please take a look at documentation at:
          /docs/cluster-howto.html  (simple how to)
          /docs/config/cluster.html (reference documentation) -->
      <!--
      <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
      -->

      <!-- 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>

      <Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">

        <!-- SingleSignOn valve, share authentication between web applications
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
        -->

        <!-- Access log processes all example.
             Documentation at: /docs/config/valve.html
             Note: The pattern used is equivalent to using pattern="common" -->
        <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"/>

      </Host>
    </Engine>
  </Service>
</Server>

context.xml: /META-INF

<?xml version="1.0" encoding="UTF-8"?>
<Context path="/Application">
  <!-- maxActive: Maximum number of database connections in pool. Make sure you
         configure your mysqld max_connections large enough to handle
         all of your db connections. Set to -1 for no limit.
         -->
  <!-- maxIdle: Maximum number of idle database connections to retain in pool.
         Set to -1 for no limit.  See also the DBCP documentation on this
         and the minEvictableIdleTimeMillis configuration parameter.
         -->
  <!-- maxWait: Maximum time to wait for a database connection to become available
         in ms, in this example 10 seconds. An Exception is thrown if
         this timeout is exceeded.  Set to -1 to wait indefinitely.
         -->
  <!-- username and password: MySQL username and password for database connections  -->
  <!-- driverClassName: Class name for the old mm.mysql JDBC driver is
         org.gjt.mm.mysql.Driver - we recommend using Connector/J though.
         Class name for the official MySQL Connector/J driver is com.mysql.jdbc.Driver.
         -->
  <!-- url: The JDBC connection url for connecting to your MySQL database.
         -->
  <resources>
    <jdbc-resource enabled="true" jndi-name="jdbc/application" object-type="user" pool-name="ApplicationPool">
      <description/>
    </jdbc-resource>
    <jdbc-connection-pool allow-non-component-callers="false" 
                          associate-with-thread="false" 
                          connection-creation-retry-attempts="0" 
                          connection-creation-retry-interval-in-seconds="10" 
                          connection-leak-reclaim="false" 
                          connection-leak-timeout-in-seconds="0" 
                          connection-validation-method="auto-commit" 
                          datasource-classname="com.mysql.jdbc.jdbc2.optional.MysqlDataSource" 
                          factory="org.apache.tomcat.jdbc.pool.DataSourceFactory" 
                          fail-all-connections="false" 
                          idle-timeout-in-seconds="300" 
                          is-connection-validation-required="false" 
                          is-isolation-level-guaranteed="true" 
                          lazy-connection-association="false" 
                          lazy-connection-enlistment="false" 
                          match-connections="false" 
                          max-connection-usage-count="0" 
                          max-pool-size="32" 
                          max-wait-time-in-millis="60000" 
                          name="ApplicationPool" 
                          non-transactional-connections="false" 
                          pool-resize-quantity="2" 
                          res-type="javax.sql.ConnectionPoolDataSource" 
                          statement-timeout-in-seconds="-1" 
                          steady-pool-size="8" 
                          validate-atmost-once-period-in-seconds="0" 
                          wrap-jdbc-objects="false">
      <description>Connects to the database</description>
      <property name="URL" value="jdbc:mysql://localhost:3306/application?zeroDateTimeBehavior=convertToNull"/>
      <property name="User" value="root"/>
      <property name="Password" value="password"/>
    </jdbc-connection-pool>
  </resources>
</Context>

第二次编辑

我在 $CATALINA_HOME/lib 中添加了这些 jar:

  • javaee-api-6.0-6.jar
  • javax.servlet.jsp.jstl-1.2.1.jar

没有 WAR 文件被分解,因为目前我在 Netbeans 8.0.2 中进行本地开发,但如果它与部署相同,服务器会自动在Web Applications 下创建一个副本(如果相同,请原谅我的无知) .

今天的日志:

WARNING:   No rules found matching 'Context/resources/jdbc-resource/description'.
Jun 23, 2015 8:10:12 PM org.apache.tomcat.util.digester.Digester endElement
WARNING:   No rules found matching 'Context/resources/jdbc-resource'.
Jun 23, 2015 8:10:12 PM org.apache.tomcat.util.digester.Digester endElement
WARNING:   No rules found matching 'Context/resources/jdbc-connection-pool/description'.
Jun 23, 2015 8:10:12 PM org.apache.tomcat.util.digester.Digester endElement
WARNING:   No rules found matching 'Context/resources/jdbc-connection-pool/property'.
Jun 23, 2015 8:10:12 PM org.apache.tomcat.util.digester.Digester endElement
WARNING:   No rules found matching 'Context/resources/jdbc-connection-pool/property'.
Jun 23, 2015 8:10:12 PM org.apache.tomcat.util.digester.Digester endElement
WARNING:   No rules found matching 'Context/resources/jdbc-connection-pool/property'.
Jun 23, 2015 8:10:12 PM org.apache.tomcat.util.digester.Digester endElement
WARNING:   No rules found matching 'Context/resources/jdbc-connection-pool'.
Jun 23, 2015 8:10:12 PM org.apache.tomcat.util.digester.Digester endElement
WARNING:   No rules found matching 'Context/resources'.
Jun 23, 2015 8:10:15 PM org.apache.openejb.config.ConfigurationFactory configureApplication
INFO: Configuring enterprise application: C:\Users\PC\Documents\NetBeansProjects\Mebzone\build\web
Jun 23, 2015 8:10:17 PM org.apache.openejb.config.AnnotationDeployer$ProcessAnnotatedBeans deploy
SEVERE: Unable to load tag library tag class: com.jsptags.navigation.pager.PagerTag
Jun 23, 2015 8:10:17 PM org.apache.openejb.config.AnnotationDeployer$ProcessAnnotatedBeans deploy
SEVERE: Unable to load tag library tag class: com.jsptags.navigation.pager.ParamTag
Jun 23, 2015 8:10:17 PM org.apache.openejb.config.AnnotationDeployer$ProcessAnnotatedBeans deploy
SEVERE: Unable to load tag library tag class: com.jsptags.navigation.pager.ItemTag
Jun 23, 2015 8:10:17 PM org.apache.openejb.config.AnnotationDeployer$ProcessAnnotatedBeans deploy
SEVERE: Unable to load tag library tag class: com.jsptags.navigation.pager.IndexTag
Jun 23, 2015 8:10:17 PM org.apache.openejb.config.AnnotationDeployer$ProcessAnnotatedBeans deploy
SEVERE: Unable to load tag library tag class: com.jsptags.navigation.pager.FirstTag
Jun 23, 2015 8:10:17 PM org.apache.openejb.config.AnnotationDeployer$ProcessAnnotatedBeans deploy
SEVERE: Unable to load tag library tag class: com.jsptags.navigation.pager.PrevTag
Jun 23, 2015 8:10:17 PM org.apache.openejb.config.AnnotationDeployer$ProcessAnnotatedBeans deploy
SEVERE: Unable to load tag library tag class: com.jsptags.navigation.pager.PageTag
Jun 23, 2015 8:10:17 PM org.apache.openejb.config.AnnotationDeployer$ProcessAnnotatedBeans deploy
SEVERE: Unable to load tag library tag class: com.jsptags.navigation.pager.PagesTag
Jun 23, 2015 8:10:17 PM org.apache.openejb.config.AnnotationDeployer$ProcessAnnotatedBeans deploy
SEVERE: Unable to load tag library tag class: com.jsptags.navigation.pager.NextTag
Jun 23, 2015 8:10:17 PM org.apache.openejb.config.AnnotationDeployer$ProcessAnnotatedBeans deploy
SEVERE: Unable to load tag library tag class: com.jsptags.navigation.pager.LastTag
Jun 23, 2015 8:10:17 PM org.apache.openejb.config.AnnotationDeployer$ProcessAnnotatedBeans deploy
SEVERE: Unable to load tag library tag class: com.jsptags.navigation.pager.SkipTag
Jun 23, 2015 8:10:17 PM org.apache.openejb.config.AnnotationDeployer$ProcessAnnotatedBeans deploy
SEVERE: Unable to load tag library tag class: com.jsptags.navigation.pager.PagerTag
Jun 23, 2015 8:10:17 PM org.apache.openejb.config.AnnotationDeployer$ProcessAnnotatedBeans deploy
SEVERE: Unable to load tag library tag class: com.jsptags.navigation.pager.ParamTag
Jun 23, 2015 8:10:17 PM org.apache.openejb.config.AnnotationDeployer$ProcessAnnotatedBeans deploy
SEVERE: Unable to load tag library tag class: com.jsptags.navigation.pager.ItemTag
Jun 23, 2015 8:10:17 PM org.apache.openejb.config.AnnotationDeployer$ProcessAnnotatedBeans deploy
SEVERE: Unable to load tag library tag class: com.jsptags.navigation.pager.IndexTag
Jun 23, 2015 8:10:17 PM org.apache.openejb.config.AnnotationDeployer$ProcessAnnotatedBeans deploy
SEVERE: Unable to load tag library tag class: com.jsptags.navigation.pager.FirstTag
Jun 23, 2015 8:10:17 PM org.apache.openejb.config.AnnotationDeployer$ProcessAnnotatedBeans deploy
SEVERE: Unable to load tag library tag class: com.jsptags.navigation.pager.PrevTag
Jun 23, 2015 8:10:17 PM org.apache.openejb.config.AnnotationDeployer$ProcessAnnotatedBeans deploy
SEVERE: Unable to load tag library tag class: com.jsptags.navigation.pager.PageTag
Jun 23, 2015 8:10:17 PM org.apache.openejb.config.AnnotationDeployer$ProcessAnnotatedBeans deploy
SEVERE: Unable to load tag library tag class: com.jsptags.navigation.pager.PagesTag
Jun 23, 2015 8:10:17 PM org.apache.openejb.config.AnnotationDeployer$ProcessAnnotatedBeans deploy
SEVERE: Unable to load tag library tag class: com.jsptags.navigation.pager.NextTag
Jun 23, 2015 8:10:17 PM org.apache.openejb.config.AnnotationDeployer$ProcessAnnotatedBeans deploy
SEVERE: Unable to load tag library tag class: com.jsptags.navigation.pager.LastTag
Jun 23, 2015 8:10:17 PM org.apache.openejb.config.AnnotationDeployer$ProcessAnnotatedBeans deploy
SEVERE: Unable to load tag library tag class: com.jsptags.navigation.pager.SkipTag

【问题讨论】:

    标签: xml tomcat jdbc configuration jndi


    【解决方案1】:

    resource.xml 不是 Apache Tomcat 配置文件。 persistence.xml 不是 Apache Tomcat 配置文件。

    server.xml 必须位于 conf 目录中。

    你有更多的 context.xml 选项,但我推荐你的 web 应用程序的 META-INF 目录。

    如果您需要有关配置的帮助,则需要提供更多信息,包括:

    • 完整的 Tomcat 版本
    • 您添加/编辑的配置文件
    • 您放置 WAR 文件/展开目录的位置
    • 您添加的任何其他 JAR 以及放置它们的位置
    • 日志中的任何错误消息

    提供上述信息后更新

    DataSource 的配置错误。 Tomcat 不支持 也不支持 标签。如果 TomEE 提供了对这些的支持,那么我无能为力(我只知道 Tomcat)。在 Tomcat 中,我希望看到一个 元素。

    对于 Tomcat(我怀疑是 TomEE),您需要在 $CATALINA_BASE/lib 中提供 MySQL JDBC 驱动程序 JAR。

    【讨论】:

    • 本教程jumpingbean.co.za/blogs/mark/… 似乎认为persistence.xml 必须像任何其他文件一样配置才能使Tomcat 工作。至于resources.xml,我以前在使用 Glassfish 时从未见过该文件。它是在我为 TomEE 创建JDBC 资源时自动创建的。我将使用上面列出的每个 XML 文件的内容来编辑我的答案。
    • 你被要求提供的其他信息呢?
    • 我编辑了我的答案。日志说WARNING: No rules found matching 'Context/resources/jdbc-connection-pool/property'. 很奇怪我用下面的代码测试了连接:
    • &lt;%@ page import="java.sql.*" %&gt; &lt;% Connection connection = null; Class.forName("com.mysql.jdbc.Driver").newInstance(); connection = DriverManager.getConnection("jdbc:mysql://localhost/&lt;DATABASE NAME&gt;?user=&lt;USERNAME&gt;&amp;password=&lt;PASSWORD&gt;"); Statement sql = connection.createStatement(); ResultSet result = sql.executeQuery("SELECT product FROM category_has_product"); while(result.next() ) { out.println(result.getString("product_id") + "&lt;br /&gt;"); } %&gt;
    • 我能够显示所有产品 ID,这是一个好兆头,表明 Tomcat 可以成功连接到数据库并检索请求的数据
    猜你喜欢
    • 2010-09-11
    • 1970-01-01
    • 2013-02-21
    • 1970-01-01
    • 2012-03-09
    • 2017-09-06
    • 2023-03-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多