繁体   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