Spring2+Struts2+Hibernate3 配置文件参考

Spring2+Struts2+Hibernate3 配置文件参考

Spring 2 配置文件
WEB-INF/classes/applicationContext.xml

 1 <? xml version="1.0" encoding="UTF-8" ?>
 2 <!--  Simple Program Spring context  -->
 3 < beans
 4      xmlns ="http://www.springframework.org/schema/beans"
 5     xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance"
 6     xsi:schemaLocation ="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd" >
 7
 8      < bean  id ="propertyConfigurer"  class ="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" >    
 9          < property  name ="location"  value ="/WEB-INF/db.properties"   />    
10      </ bean >
11
12      < bean  id ="dataSource"  class ="org.apache.commons.dbcp.BasicDataSource" >
13          < property  name ="driverClassName"  value ="${db.driver}"   />
14          < property  name ="url"  value ="${db.url}"   />
15          < property  name ="username"  value ="${db.username}"   />
16          < property  name ="password"  value ="${db.password}"   />
17      </ bean >
18     
19      < bean  id ="sessionFactory"  class ="org.springframework.orm.hibernate3.LocalSessionFactoryBean" >
20          < property  name ="dataSource" >
21              < ref  bean ="dataSource"   />
22          </ property >
23          < property  name ="hibernateProperties" >
24              < props >
25                  < prop  key ="hibernate.dialect" > org.hibernate.dialect.MySQLDialect </ prop >
26              </ props >
27          </ property >
28          < property  name ="mappingResources" >
29              < list >< value > simplepro/per/model/Contact.hbm.xml </ value ></ list >
30          </ property >
31      </ bean >
32     
33      < bean  id ="ContactDAO"  class ="simplepro.per.dao.hibernate.ContactDAOHibImpl" >
34          < property  name ="sessionFactory" >
35              < ref  bean ="sessionFactory"   />
36          </ property >
37      </ bean >
38     
39      < bean  id ="ContactService"  class ="simplepro.service.impl.ContactServiceImpl" >
40          < property  name ="contactDAO" >
41              < ref  bean ="ContactDAO"   />
42          </ property >
43      </ bean >
44     
45      < bean  id ="ContactAction"  class ="simplepro.web.action.ContactAction"  scope ="prototype" >
46          < property  name ="contactService" >
47              < ref  bean ="ContactService"   />
48          </ property >
49      </ bean >
50
51 </ beans >

Struts2 配置文件
WEB-INF/classes/Struts2.xml

 1 <? xml version="1.0" encoding="UTF-8"  ?>
 2
 3 <! DOCTYPE struts PUBLIC
 4     "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
 5     "http://struts.apache.org/dtds/struts-2.0.dtd" >
 6
 7 < struts >
 8
 9      < package  name ="simplepro"  extends ="struts-default" >
10          < action  name ="index"  class ="ContactAction"  method ="execute" >
11              < result  name ="success" > /WEB-INF/jsp/contacts.jsp </ result >
12          </ action >
13          < action  name ="add"  class ="ContactAction"  method ="add" >
14              < result > /WEB-INF/jsp/contacts.jsp </ result >
15              < result  name ="input" > /WEB-INF/jsp/addcontact.jsp </ result >
16          </ action >
17          < action  name ="update"  class ="ContactAction"  method ="update" >
18              < result > /WEB-INF/jsp/contacts.jsp </ result >
19              < result  name ="input" > /WEB-INF/jsp/updatecontact.jsp </ result >
20          </ action >
21          < action  name ="delete"  class ="ContactAction"  method ="delete" >
22              < result > /WEB-INF/jsp/contacts.jsp </ result >
23              < result  name ="input" > /WEB-INF/jsp/contacts.jsp </ result >
24          </ action >
25          < action  name ="lookup"  class ="ContactAction"  method ="lookup" >
26              < result > /WEB-INF/jsp/contacts.jsp </ result >
27          </ action >
28          < action  name ="load"  class ="ContactAction"  method ="load" >
29              < result > /WEB-INF/jsp/updatecontact.jsp </ result >
30              < result  name ="input" > /WEB-INF/jsp/contacts.jsp </ result >
31          </ action >
32      </ package >
33
34 </ struts >

Struts2 properties 配置文件 (与Spring集成, 将IOC交给Spring完成)
WEB-INF/classes/Struts2.properties

struts.objectFactory = spring

Database properties 配置文件
WEB-INF/db.properties

db.username = root
db.password
= root
db.url
= jdbc:mysql://localhost: 3306 /simplepro
db.driver
= com.mysql.jdbc.Driver


 

你可能感兴趣的:(Spring2+Struts2+Hibernate3 配置文件参考)