<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
涔嬪悗灝卞彲浠ュ湪紼嬪簭浣跨敤浜?/p>
public HttpServletRequest getHttpServletRequest()
FileSystemXmlApplicationContext
XmlWebApplicationContext
鍏朵腑 XmlWebApplicationContext鏄笓涓?/font>Web宸ョ▼瀹氬埗鐨勩備嬌鐢ㄤ婦渚嬪涓嬶細(xì)
//鍔犺澆澶氫釜鏂囦歡
String[] Local={"classpath:applicationContext.xml"};
//榪欐槸鏀懼湪src涓嬶紝鎵浠ョ敤classpath: 褰撶劧浣犱篃鍙互涓嶇敤
//絎竴縐嶆柟寮?/span>
ApplicationContext context=new FileSystemXmlApplicationContext(Local);
//絎簩縐嶆柟寮?/font>
context= new ClassPathXmlApplicationContext(Local);
榪欎袱縐嶆柟寮忎竴鑸敤浜庡湪Action涓垨鑰?/font>Manager涓幏寰楀叾浠栫殑Manager
絎笁縐嶆柟寮忥細(xì)
鍦?font face="Arial">web.xml涓厤緗?/font>
閰嶇疆鐩戝惉鍣細(xì)
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener </listener-class>
</listener>
閰嶇疆鐩戝惉鍣ㄧ洃鍚殑xml
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
Jsp涓鐞嗭細(xì)
<%
//絎笁縐嶆柟寮?/span>
ServletContext servletContext = request.getSession().getServletContext();
ApplicationContext ctx=WebApplicationContextUtils.getWebApplicationContext(servletContext);
out.println(ctx);//嫻嬭瘯
%>
榪欑鏂瑰紡涓鑸敤浜庡湪jsp涓彇Manager,褰撶劧鍏朵粬鐨勪綘鑳?/font>get鍒扮殑 閮藉彲浠ヨ幏寰?/font>
jsp 涓鍏ョ殑鍖?/span> <%@ page import="org.springframework.web.context.support.WebApplicationContextUtils,org.springframework.context.ApplicationContext" %>
<!-- 瀹氫箟Hibernate鐨?/span>sessionFactory錛岄氳繃璇?/span>Bean錛屽彲浠ヨ幏寰?/span>Hibernate鐨?/span>Session-->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="lobHandler">
<ref bean="lobHandler"/>
</property>
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<!--璁劇疆浜岀駭緙撳啿-->
<prop key="hibernate.cache.provider_class">
org.hibernate.cache.EhCacheProvider
</prop>
<!--璁劇疆浜岀駭緙撳啿錛屾墦寮鏌ヨ緙撳啿-->
<prop key="hibernate.cache.use_query_cache">true</prop>
<!--璁劇疆鏄劇ずHibernate鎿嶄綔鐨?/span>SQL璇彞-->
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>
com/njwj/model/test.hbm.xml
</value>
</list>
</property>
</bean>
<!-- 鐢蟲槑澶勭悊Clob瀵硅薄LobHandler -->
<bean id="lobHandler" class="org.springframework.jdbc.support.lob.DefaultLobHandler" lazy-init="true" />
鍦?/span>hibernate瀹炰綋綾婚厤緗腑
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping package="com.njwj.model">
<class name="LobHandlerTest" table="lobhandlertest">
<id name="id" column="id">
<generator class="native"></generator>
</id>
<property name="lobhandler" column="lobhandler" type="org.springframework.orm.hibernate3.support.ClobStringType" length="200"></property>
</class>
</hibernate-mapping>
name="lobhandler" 涓哄疄浣撶被灞炴?/span> 涓?/span>String綾誨瀷
column="lobhandler" 涓烘暟鎹簱瀛楁涓?/span>Clob綾誨瀷
*.hbm.xml閰嶇疆淇敼濡備笅:
a:鎿嶄綔blob,java綾葷殑鎴愬憳鍙橀噺綾誨瀷璁劇疆涓?/span>byte[],鏄犲皠鏂囦歡璁劇疆涓猴細(xì)
org.springframework.orm.hibernate3.support.BlobByteArrayType
b:鎿嶄綔clob,java綾葷殑鎴愬憳鍙橀噺綾誨瀷璁劇疆涓?/span>String,鏄犲皠鏂囦歡璁劇疆涓猴細(xì)
org.springframework.orm.hibernate3.support.ClobStringType