Spring、Hibernate、Proxool整合配置

主要配置信息在两个文件中,一个XML,一个Properties,并在Web.xml中展示Proxool自带的控制台。

 

 

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

	<bean id="propertyConfig"
		class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="locations">
			<list>
                                 <!---properties文件-->
				<value>classpath:migle.properties</value>
			</list>
		</property>
	</bean>

	<bean id="dataSource" class="org.logicalcobwebs.proxool.ProxoolDataSource">
		<property name="alias" value="spring-proxool" />
		<property name="driver">
			<value>${jdbc.default.driverClassName}</value>
		</property>
		<property name="driverUrl">
			<value>${jdbc.default.url}</value>
		</property>
		<property name="user" value="${jdbc.default.username}" />
		<property name="password" value="${jdbc.default.password}"></property>
		<property name="prototypeCount">
			<value>5</value>
		</property>
		<property name="maximumConnectionCount" value="${proxool.maximumConnectionCount}" />
		<property name="minimumConnectionCount" value="${proxool.minimumConnectionCount}" />
		<property name="houseKeepingTestSql" value="${proxool.houseKeepingTestSql}" />
		<property name="trace">
			<value>true</value>
		</property>
		<property name="verbose">
			<value>true</value>
		</property>

		<!--
			<property name="driver"> <value>com.mysql.jdbc.Driver</value>
			</property> <property name="driverUrl">
			<value>jdbc:mysql://localhost:3306/nxjdf?user=root&amp;password=12345</value>
			</property> <property name="user" value="root" /> <property
			name="password" value="12345" />
		-->

	</bean>

	<bean id="sessionFactory"
		class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<property name="mappingResources">
			<list>
<!---Hibernate映射文件列表--->
 <value>org/migle/persister/model/User.hbm.xml
				</value>
			</list>
		</property>
				<property name="hibernateProperties">
			<props>
				<prop key="hibernate.dialect">${hibernate.dialect}</prop>
				<!--根据映射Hibernate映射文件每次启动时创建数据库 -->
				<prop key="hbm2ddl.auto">create</prop>
				<!--
					<prop key="proxool.pool_alias">spring-proxool</prop> <prop
					key="connection.provider_class">org.hibernate.connection.ProxoolConnectionProvider</prop>
				-->
			</props>
		</property>
	</bean>
</beans>

 

migle.properties

 

#######------JDBC---------------------############################
 #MySQL
   jdbc.default.driverClassName=com.mysql.jdbc.Driver
   jdbc.default.url=jdbc:mysql://localhost/hbm?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
   jdbc.default.username=root
   jdbc.default.password=12345
   hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect
   
 #Oracle
   #jdbc.default.driverClassName=oracle.jdbc.driver.OracleDriver
   #jdbc.default.url=jdbc:oracle:thin:migle/[email protected]:1521:orcl
   #jdbc.default.username=migle
   #jdbc.default.password=longforfreedom
   #hibernate.dialect=org.hibernate.dialect.OracleDialect
   
 #PostgreSQL
   #
   #jdbc.default.driverClassName=org.postgresql.Driver
   #jdbc.default.url=jdbc:postgresql://10.180.85.205:5432/DB
   #jdbc.default.username=postgres
   #jdbc.default.password=km12345
   #hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
   #
# SQL Server
   #
   #jdbc.default.driverClassName=net.sourceforge.jtds.jdbc.Driver
   #jdbc.default.url=jdbc:jtds:sqlserver://localhost/nxjdf
   #jdbc.default.username=sa
   #jdbc.default.password=org.hibernate.dialect.SQLServerDialect
   
#######------proxool---------------------############################
proxool.houseKeepingTestSql=select now()
proxool.maximumConnectionCount=100
proxool.minimumConnectionCount=10
 

 

web.xml配置示例

 

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee   http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
 <context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>classpath:applicationContext.xml</param-value>
 </context-param>
 <listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
 </listener>
 <servlet>
<!---proxool自带的监控-->
  <description>proxool 监控</description>
  <display-name>proxool admin</display-name>
  <servlet-name>proxooladmin</servlet-name>
  <servlet-class>org.logicalcobwebs.proxool.admin.servlet.AdminServlet</servlet-class>
  <load-on-startup>0</load-on-startup>
 </servlet>

 <servlet-mapping>
  <servlet-name>proxooladmin</servlet-name>
  <url-pattern>/admin/proxool</url-pattern>
 </servlet-mapping>

 
 <session-config>
  <session-timeout>60</session-timeout>
 </session-config>

</web-app>
 

 

 

你可能感兴趣的:(spring,Hibernate,mysql,jdbc,servlet)