簡體   English   中英

Tomcat連接池-出廠設置

[英]Tomcat Connection Pool - Factory Setting

我一直在學習如何通過建立Tomcat的連接池這個網站。 所以我做了一個context.xml文件,並把它放在目錄META-INF。 這就是我現在所擁有的。

<?xml version="1.0" encoding="UTF-8"?>

<Context>
    <Resource name="jdbc/gmustudent" auth="Container"
        type="javax.sql.DataSource" driverClassName="com.mysql.jdbc.Driver"
        username="root" password="root"
        url="jdbc:mysql://localhost:3306/official"
        maxActive="100" maxIdle="10" minIdle="5" initialSize="5" maxWait="10000" />
</Context>

但是我想指定工廠的類名。 但是每次我添加此屬性

factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"

我的控制台出現了很多錯誤。 以下是其中一些按特定順序排列的內容。

WARNING: Failed to register in JMX: javax.naming.NamingException: com.mysql.jdbc.Driver
WARNING: Unexpected exception resolving reference java.sql.SQLException: com.mysql.jdbc.Driver
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:gmustudent' did not find a matching property.

因此,當我不指定工廠時,該站點就可以正常工作。 但是當我這樣做時,會拋出錯誤,並且沒有任何效果。 我對堆棧溢出進行了一些研究,並找到了這篇文章。 因此,我將tomcat版本從7.0.11更改為最新版本,但仍然出現錯誤。 因此,我以為也許與server.xml文件中的工廠存在某種沖突,但是我幾乎沒有經驗進行該調用。 但是這是我的server.xml文件中的資源

<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"/>

那么這與我的context.xml文件中的工廠是否沖突? 還是我在這里完全錯了? 簡而言之,我想了解如何在我的context.xml文件中指定工廠,而不會出現大錯誤。 感謝您的閱讀。

如果需要,您實際上可以使用Spring在Web應用程序中管理整個連接。 這是使用PostgreSQL的示例:

<?xml version="1.0" encoding="windows-1252"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
    <bean id="myDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="org.postgresql.Driver"/>
        <property name="url" value="jdbc:postgresql://localhost/mydb"/>
        <property name="username" value="postgres"/>
        <property name="password" value="postgres"/>
    </bean>
</beans>

您可以將其放在WEB-INF / classs中並使用以下命令加載它:

ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("/mycontext.xml");

在這一點上,我什至不願意讓Tomcat管理它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM