一、springXML配置文件
<?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"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd">
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<!-- <property name="dataSource">
<ref bean="dataSource" />
</property> -->
<property name="configLocation" value="classpath:hibernate.cfg.xml" />
</bean>
<context:component-scan base-package="com.enjoy.traffic.deal"></context:component-scan>
</beans>
二、hibernate.cfg.xml配置文件
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- 方言 -->
<property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>
<!-- oracle驱动 -->
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<!-- JDBC URL -->
<property name="connection.url">jdbc:oracle:thin:@192.168.10.224:1521:MCSJT</property>
<!-- 数据库用户名-->
<property name="connection.username">MCS_JT</property>
<!-- 数据库密码-->
<property name="connection.password">MCS_JT</property>
<!-- 设置是否显示SQL语句-->
<property name="show_sql">true</property>
<!-- 设置是否格式化SQL语句 -->
<property name="format_sql">true</property>
<!-- 设置使用线程-->
<property name="current_session_context_class">thread</property>
<!-- <mapping resource="hibernate/vo/user.xml"/> -->
</session-factory>
</hibernate-configuration>
三,web监听
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
public class ServerStart implements ServletContextListener{
@Override
public void contextDestroyed(ServletContextEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void contextInitialized(ServletContextEvent arg0) {
// TODO Auto-generated method stub
System.out.println("start server ...");
WebApplicationContext application = WebApplicationContextUtils.getWebApplicationContext(arg0.getServletContext());
WaterDeal waterDeal = (WaterDeal)application.getBean("waterDeal");
waterDeal.cad();
}
}
四、hibernate动态导入