我用ssh架构 Tomcat服务器 如何实现开启Tomcat同时启动c3p0连接池?

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【gna15】截止到2008-06-26 15:54:39的历史汇总数据(不包括此帖):
    发帖数:5                  发帖分:100                
    结贴数:3                  结贴分:60                 
    未结数:2                  未结分:40                 
    结贴率:60.00 %            结分率:60.00 %            
    楼主加油
      

  2.   

    你配置了c3p0连接池后,服务器启动的时候,会自动初始化spring配置,spring初始化hibernate配置,hibernate初始化c3p0,同时开放最小连接数个链接在你的applicationContext.xml中配置,主要参照以下例子
    ......
    <bean id="mySessionFactory"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="mappingDirectoryLocations">
    <list>
    <value>classpath:/com/lan/adms/resource/hbm</value>
    </list>
    </property>
    <property name="lobHandler">
    <ref bean="lobhandler" />
    </property>
    <property name="hibernateProperties">
    <value>
      <!-- c3p0连接池配置方法 -->
       hibernate.connection.driver_class = com.microsoft.sqlserver.jdbc.SQLServerDriver
    hibernate.connection.url = jdbc:sqlserver://localhost:1433; DatabaseName=adms
    hibernate.connection.username = sa
    hibernate.connection.password = 123456
    hibernate.c3p0.min_size=5
    hibernate.c3p0.max_size=20
    hibernate.c3p0.timeout=1800
    hibernate.c3p0.max_statements=50
    hibernate.show_sql=true
    hibernate.dialect=org.hibernate.dialect.SQLServerDialect
    </value>
    </property>
    </bean>
    ......
    前提是把c3p0包拷贝到你的classpath下
      

  3.   

    我的c3p0可以使用  想知道怎么开启Tomcat时启动c3p0
      

  4.   

    我不是说过了吗,你不是用的ssh吗,那你的web.xml里面应该已经初始化spring的配置了
    <listener>
    <listener-class>
    org.springframework.web.context.ContextLoaderListener
    </listener-class>
    </listener>tomcat启动的时候,会自动初始化spring配置,spring初始化hibernate配置,hibernate初始化c3p0,也就是启动的意思,同时开放最小连接数个链接 
      

  5.   

    有办法让它显示在后台吗?就像下面这样这样2008-6-27 9:49:18 org.apache.catalina.storeconfig.StoreLoader load
    信息: Find registry server-registry.xml at classpath resource
    2008-6-27 9:49:18 org.apache.catalina.startup.Catalina start
    信息: Server startup in 5453 ms
    Initializing c3p0 pool... com.mchange.v2.c3p0.PoolBackedDataSource@12368df [ connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@104e28b [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, idleConnectionTestPeriod -> 900, initialPoolSize -> 3, maxIdleTime -> 600, maxPoolSize -> 50, maxStatements -> 100, maxStatementsPerConnection -> 0, minPoolSize -> 2, nestedDataSource -> com.mchange.v2.c3p0.DriverManagerDataSource@ae4646 [ description -> null, driverClass -> com.mysql.jdbc.Driver, factoryClassLocation -> null, jdbcUrl -> jdbc:mysql://localhost:3306/ogms?useUnicode=true&characterEncoding=GBK, properties -> {user=******, password=******} ] , preferredTestQuery -> null, propertyCycle -> 300, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, usesTraditionalReflectiveProxies -> false ] , factoryClassLocation -> null, numHelperThreads -> 10, poolOwnerIdentityToken -> 12368df ] 
      

  6.   

    要显示信息,配置log4j就行,这个网上一搜就太多了。
      

  7.   

    配置到server.xml文件里就可以看到那一堆的信息了
      

  8.   

    配置log4j吧,到你的spring的lib\log4j下,把log4j-x.x.x.jar拷贝到你的classpath下然后再上spring的test下把log4j.properties,拷贝到你的src源文件夹下打开把log4j.rootLogger=WARN, stdout 改成log4j.rootLogger=DEBUG, stdout启动tomcat,你会看到里面有如下的部分内容13:44:43,796  INFO AbstractPoolBackedDataSource:462 - Initializing c3p0 pool... com.mchange.v2.c3p0.PoolBackedDataSource@1de0df44 [ connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@111a87d5 [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, debugUnreturnedConnectionStackTraces -> false, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 2udulj7u1jn9au1g5doyp|8bca43, idleConnectionTestPeriod -> 0, initialPoolSize -> 5, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 1800, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 20, maxStatements -> 50, maxStatementsPerConnection -> 0, minPoolSize -> 5, nestedDataSource -> com.mchange.v2.c3p0.DriverManagerDataSource@11de7336 [ description -> null, driverClass -> null, factoryClassLocation -> null, identityToken -> 2udulj7u1jn9au1g5doyp|95fa7f, jdbcUrl -> jdbc:sqlserver://localhost:1433; DatabaseName=adms, properties -> {user=******, password=******, release_mode=on_close} ], preferredTestQuery -> null, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false; userOverrides: {} ], dataSourceName -> null, factoryClassLocation -> null, identityToken -> 2udulj7u1jn9au1g5doyp|24b943, numHelperThreads -> 3 ]
    13:44:44,015 DEBUG BasicResourcePool:404 - incremented pending_acquires: 1
    13:44:44,015 DEBUG BasicResourcePool:404 - incremented pending_acquires: 2
    13:44:44,015 DEBUG BasicResourcePool:404 - incremented pending_acquires: 3
    13:44:44,015 DEBUG BasicResourcePool:404 - incremented pending_acquires: 4
    13:44:44,031 DEBUG BasicResourcePool:404 - incremented pending_acquires: 5