随笔-179  评论-666  文章-29  trackbacks-0
1.applicationContext.xml 文件的配制:

 1<?xml version="1.0" encoding="UTF-8"?> 
 2<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> 
 3
 4<beans> 
 5
 6<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> 
 7    
 8        <property name="driverClassName"> 
 9            <value>com.mysql.jdbc.Driver</value> 
10        </property> 
11    
12        <property name="url"> 
13            <value>jdbc:mysql://192.168.2.186/task</value> 
14        </property> 
15
16        <property name="username"> 
17            <value>task</value> 
18        </property> 
19    
20        <property name="password"> 
21            <value>123</value> 
22        </property> 
23    </bean> 
24
25    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" singleton="true"> 
26
27        <property name="dataSource"> 
28            <ref local="dataSource" /> 
29        </property> 
30    
31        <property name="mappingResources"> 
32            <list>                 
33                <value>com/task/hibernatemap/xml/UserInfo.hbm.xml</value>    
34                <value>com/task/hibernatemap/xml/Apply.hbm.xml</value>
35                <value>com/task/hibernatemap/xml/Approve.hbm.xml</value>
36                <value>com/task/hibernatemap/xml/Discription.hbm.xml</value>
37                <value>com/task/hibernatemap/xml/Person.hbm.xml</value>
38                <value>com/task/hibernatemap/xml/ItemName.hbm.xml</value>    
39                <value>com/task/hibernatemap/xml/ItemVersion.hbm.xml</value>
40            </list> 
41        </property> 
42
43        <property name="hibernateProperties"> 
44            <props> 
45            <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> 
46            <prop key="hibernate.show_sql">false</prop> 
47            </props> 
48        </property> 
49    </bean> 
50        
51    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> 
52        <property name="sessionFactory"> 
53            <ref local="sessionFactory" /> 
54        </property> 
55    </bean> 
56    
57    <bean id="hibernateDao"     class="com.task.common.HibernateDao"> 
58        <property name="sessionFactory"> 
59            <ref local="sessionFactory" /> 
60        </property> 
61        <property name="transactionManager">
62            <ref local="transactionManager" />
63        </property>
64    </bean> 
65        
66    <bean id="hibernateDaoProxy"  singleton="true" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> 
67        <property name="transactionManager"> 
68            <ref bean="transactionManager" /> 
69        </property> 
70
71        <property name="target"> 
72            <ref local="hibernateDao" /> 
73        </property> 
74    
75        <property name="transactionAttributes"> 
76            <props>
77                <prop key="save*">PROPAGATION_REQUIRED</prop>  
78                <prop key="remove*">PROPAGATION_REQUIRED</prop>  
79                <prop key="update*">PROPAGATION_REQUIRED</prop>  
80                <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>  
81            </props> 
82        </property> 
83    </bean> 
84    
85</beans> 
86

2.web.xml 文件的配制:

 1<?xml version="1.0" encoding="ISO-8859-1"?>
 2
 3<!DOCTYPE web-app
 4    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 5    "http://java.sun.com/dtd/web-app_2_3.dtd">
 6
 7<web-app>
 8    
 9    <filter>
10        <filter-name>openSessionInViewFilter</filter-name>
11        <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
12    </filter>
13    <filter-mapping>
14        <filter-name>openSessionInViewFilter</filter-name>
15        <url-pattern>/*</url-pattern>
16    </filter-mapping>
17    
18    <listener>
19        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
20    </listener>
21
22
23    <servlet>
24        <servlet-name>task</servlet-name>
25        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
26        <load-on-startup>1</load-on-startup>
27    </servlet>
28
29    <servlet-mapping>
30        <servlet-name>task</servlet-name>
31        <url-pattern>*.job</url-pattern>
32    </servlet-mapping>
33
34    <welcome-file-list>
35        <welcome-file>index.jsp</welcome-file>
36    </welcome-file-list>
37</web-app>

3.task-servlet.xml 文件的配制:

 1<?xml version="1.0" encoding="UTF-8"?>
 2<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
 3
 4<beans>        
 5    
 6    <bean id="listController" class="com.task.controller.ListController">
 7        <property name="defaultPage"><value>/list</value></property>
 8    </bean>
 9    
10        
11    <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
12        <property name="mappings">
13            <props>
14                <prop key="/list*">listController</prop>            
15            </props>
16        </property>    
17    </bean>
18
19    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
20        <property name="viewClass">
21            <value>org.springframework.web.servlet.view.JstlView</value>
22        </property>
23        <property name="suffix"><value>.jsp</value></property>
24    </bean>
25            
26</beans>
27

需要注意的是,第三个文件的文件名一定要与第二个文件中黄色字体名字一样!



posted on 2006-02-10 09:54 Alpha 阅读(1318) 评论(3)  编辑  收藏 所属分类: Spring

评论:
# re: Spring+Hibernate的配制 2006-02-13 12:34 | Jet Geng
好东西。mappingResources这个属性我找了很久了。呵呵。
谢谢了

  回复  更多评论
  
# re: Spring+Hibernate的配制 2006-03-16 11:39 | liuzhiwen
明显就是橙色,华哥,你不行啊  回复  更多评论
  
# re: Spring+Hibernate的配制[未登录] 2010-05-22 09:20 | aa
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航: