基于Struts+Spring+Hibernate的Blog系统--配置

applicationContext.xml
    1    <?  xml version = " 1.0 "  encoding = " UTF-8 "   ?>  
 
2    <!  DOCTYPE beans PUBLIC  " -//SPRING//DTD BEAN//EN "
 
3       " http://www.springframework.org/dtd/spring-beans.dtd "   >  
 
4   
 
5    <  beans  >  
 
6        <  bean  id  = " propertyConfigurer "  
 
7           class   = " org.springframework.beans.factory.config.PropertyPlaceholderConfigurer "   >  
 
8            <  property  name  = " location "   value  = " classpath:jdbc.properties "     />  
 
9        </  bean  >  
10   
11        <!--   Transaction template  for  Managers, from:
12          http: // blog.exis.com/colin/archives/2004/07/31/concise-transaction-definitions-spring-11/  --> 
13        <  bean  id  = " txProxyTemplate "    abstract   = " true "  
14           class   = " org.springframework.transaction.interceptor.TransactionProxyFactoryBean "   >  
15            <  property  name  = " transactionManager "   >  
16                <  ref  bean  = " transactionManager "     />  
17            </  property  >  
18            <  property  name  = " transactionAttributes "   >  
19                <  props  >  
20                    <  prop  key  = " save* "   >  PROPAGATION_REQUIRED  </  prop  >  
21                    <  prop  key  = " remove* "   >  PROPAGATION_REQUIRED  </  prop  >  
22                    <  prop  key  = " * "   >  PROPAGATION_REQUIRED,readOnly  </  prop  >  
23                </  props  >  
24            </  property  >  
25        </  bean  >  
26   
27        <  bean  id  = " userManager "   parent  = " txProxyTemplate "   >  
28            <  property  name  = " target "   >  
29                <  bean   class   = " com.weblog.service.impl.UserManagerImpl "   >  
30                    <  property  name  = " userDAO "   ref  = " userDAO "     />  
31                </  bean  >  
32            </  property  >  
33        </  bean  >  
34        <!--  Author - START  -->  
35        <  bean  id  = " authorManager "   parent  = " txProxyTemplate "   >  
36            <  property  name  = " target "   >  
37                <  bean   class   = " com.weblog.service.impl.AuthorManagerImpl "   >  
38                    <  property  name  = " authorDao "   ref  = " authorDao "     />  
39                </  bean  >  
40            </  property  >  
41        </  bean  >  
42        <!--  Author - END  -->  
43        <!--  Category - START  -->  
44        <  bean  id  = " categoryManager "   parent  = " txProxyTemplate "   >  
45            <  property  name  = " target "   >  
46                <  bean   class   = " com.weblog.service.impl.CategoryManagerImpl "   >  
47                    <  property  name  = " categoryDao "   ref  = " categoryDao "     />  
48                </  bean  >  
49            </  property  >  
50        </  bean  >  
51        <!--  Category - END  -->  
52        <!--  Weblog - START  -->  
53        <  bean  id  = " weblogManager "   parent  = " txProxyTemplate "   >  
54            <  property  name  = " target "   >  
55                <  bean   class   = " com.weblog.service.impl.WeblogManagerImpl "   >  
56                    <  property  name  = " weblogDao "   ref  = " weblogDao "     />  
57                </  bean  >  
58            </  property  >  
59        </  bean  >  
60        <!--  Weblog - END  -->  
61      
62    </  beans  >  
action - servlet.xml
1    <?  xml version = " 1.0 "  encoding = " UTF-8 "   ?>  
 
2    <!  DOCTYPE beans PUBLIC  " -//SPRING//DTD BEAN//EN "
 
3       " http://www.springframework.org/dtd/spring-beans.dtd "   >  
 
4   
 
5    <  beans  >  
 
6        <  bean  name  = " /user "    class   = " com.weblog.web.UserAction "  
 
7          singleton  = " false "   >  
 
8            <  property  name  = " userManager "   ref  = " userManager "     />  
 
9        </  bean  >  
10        <  bean  name  = " /author "    class   = " com.weblog.web.AuthorAction "  
11          singleton  = " false "   >  
12            <  property  name  = " authorManager "   ref  = " authorManager "     />  
13        </  bean  >  
14        <  bean  name  = " /category "    class   = " com.weblog.web.CategoryAction "  
15          singleton  = " false "   >  
16            <  property  name  = " categoryManager "   ref  = " categoryManager "     />  
17        </  bean  >  
18        <  bean  name  = " /weblog "    class   = " com.weblog.web.WeblogAction "  
19          singleton  = " false "   >  
20            <  property  name  = " weblogManager "   ref  = " weblogManager "     />  
21        </  bean  >  
22    </  beans  >  
applicationContext - hibernate.xml
1    <?  xml version = " 1.0 "  encoding = " UTF-8 "   ?>  
 
2    <!  DOCTYPE beans PUBLIC  " -//SPRING//DTD BEAN//EN "
 
3       " http://www.springframework.org/dtd/spring-beans.dtd "   >  
 
4   
 
5    <  beans  >  
 
6        <  bean  id  = " dataSource "  
 
7           class   = " org.springframework.jdbc.datasource.DriverManagerDataSource "   >  
 
8            <  property  name  = " driverClassName "  
 
9              value  = " ${jdbc.driverClassName} "     />  
10            <  property  name  = " url "   value  = " ${jdbc.url} "     />  
11            <  property  name  = " username "   value  = " ${jdbc.username} "     />  
12            <  property  name  = " password "   value  = " ${jdbc.password} "     />  
13        </  bean  >  
14   
15        <  bean  id  = " sessionFactory "  
16           class   = " org.springframework.orm.hibernate3.LocalSessionFactoryBean "   >  
17            <  property  name  = " dataSource "   ref  = " dataSource "     />  
18            <  property  name  = " mappingResources "   >  
19                <  list  >  
20                    <  value  >  com / weblog / model / User.hbm.xml  </  value  >  
21                    <  value  >  com / weblog / model / Author.hbm.xml  </  value  >  
22                    <  value  >  com / weblog / model / Category.hbm.xml  </  value  >  
23                    <  value  >  com / weblog / model / Weblog.hbm.xml  </  value  >  
24                </  list  >  
25            </  property  >  
26            <  property  name  = " hibernateProperties "   >  
27                <  props  >  
28                    <  prop  key  = " hibernate.dialect "   >  
29                      org.hibernate.dialect.PostgreSQLDialect
30                    </  prop  >  
31                    <  prop  key  = " hibernate.hbm2ddl.auto "   >  update  </  prop  >  
32                </  props  >  
33            </  property  >  
34        </  bean  >  
35   
36        <  bean  id  = " transactionManager "  
37           class   = " org.springframework.orm.hibernate3.HibernateTransactionManager "   >  
38            <  property  name  = " sessionFactory "   ref  = " sessionFactory "     />  
39        </  bean  >  
40   
41        <  bean  id  = " userDAO "  
42           class   = " com.weblog.dao.hibernate.UserDAOHibernate "   >  
43            <  property  name  = " sessionFactory "   ref  = " sessionFactory "     />  
44        </  bean  >  
45        <  bean  id  = " authorDao "  
46           class   = " com.weblog.dao.hibernate.AuthorDaoHibernate "   >  
47            <  property  name  = " sessionFactory "   ref  = " sessionFactory "     />  
48        </  bean  >  
49   
50        <  bean  id  = " categoryDao "  
51           class   = " com.weblog.dao.hibernate.CategoryDaoHibernate "  
52          autowire  = " byName "     />  
53        <  bean  id  = " weblogDao "  
54           class   = " com.weblog.dao.hibernate.WeblogDaoHibernate "   >  
55            <  property  name  = " sessionFactory "   ref  = " sessionFactory "     />  
56        </  bean  >  
57   
58    </  beans  >  
jdbc.properties
1   jdbc.driverClassName = org.postgresql.Driver
2  jdbc.url = jdbc:postgresql: // localhost/weblog
3  jdbc.username = postgres
4  jdbc.password = password 
struts - config.xml 
1    <?  xml version = " 1.0 "  encoding = " UTF-8 "   ?>  
  
2    <!  DOCTYPE struts - config PUBLIC
  
3       " -//Apache Software Foundation//DTD Struts Configuration 1.1//EN "
  
4       " http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd "   >  
  
5   
  
6    <  struts - config  >  
  
7   
  
8        <!--    ========================================  Form Bean Definitions   -->  
  
9   
 
10        <  form - beans  >  
 
11            <  form - bean  name  = " userForm "  
 
12              type  = " org.apache.struts.validator.DynaValidatorForm "   >  
 
13                <  form - property  name  = " user "   type  = " com.weblog.model.User "     />  
 
14            </  form - bean  >  
 
15            <  form - bean  name  = " authorForm "  
 
16              type  = " org.apache.struts.validator.DynaValidatorForm "   >  
 
17                <  form - property  name  = " author "   type  = " com.weblog.model.Author "     />  
 
18            </  form - bean  >  
 
19            <  form - bean  name  = " categoryForm "  
 
20              type  = " org.apache.struts.validator.DynaValidatorForm "   >  
 
21                <  form - property  name  = " category "  
 
22                  type  = " com.weblog.model.Category "     />  
 
23            </  form - bean  >  
 
24            <  form - bean  name  = " weblogForm "  
 
25              type  = " org.apache.struts.validator.DynaValidatorForm "   >  
 
26                <  form - property  name  = " weblog "   type  = " com.weblog.model.Weblog "     />  
 
27            </  form - bean  >  
 
28        </  form - beans  >  
 
29   
 
30        <!--    ===================================  Global Exception Definitions   -->  
 
31        <  global - exceptions  >  
 
32            <  exception  key  = " error.required "  
 
33              type  = " org.springframework.dao.DataAccessException "  
 
34              path  = " /dataAccessFailure.jsp "     />  
 
35        </  global - exceptions  >  
 
36   
 
37        <!--    ===================================  Global Forward Definitions   -->  
 
38   
 
39        <  global - forwards  >  
 
40            <  forward  name  = " users "   path  = " /users.html "   redirect  = " true "     />  
 
41            <  forward  name  = " authors "   path  = " /authors.html "   redirect  = " true "     />  
 
42            <  forward  name  = " weblogs "   path  = " /weblogs.html "   redirect  = " true "     />  
 
43            <  forward  name  = " categorys "   path  = " /categorys.html "  
 
44              redirect  = " true "     />  
 
45        </  global - forwards  >  
 
46   
 
47        <!--    ===================================  Action Mapping Definitions   -->  
 
48   
 
49        <  action - mappings  >  
 
50   
 
51            <  action  path  = " /users "  
 
52              type  = " org.apache.struts.actions.ForwardAction "  
 
53              parameter  = " /user.html "     />  
 
54   
 
55            <  action  path  = " /user "  
 
56              type  = " org.springframework.web.struts.DelegatingActionProxy "  
 
57              name  = " userForm "   scope  = " request "   parameter  = " method "  
 
58              validate  = " false "   >  
 
59                <  forward  name  = " list "   path  = " /userList.jsp "     />  
 
60                <  forward  name  = " edit "   path  = " /userForm.jsp "     />  
 
61            </  action  >  
 
62            <  action  path  = " /authors "  
 
63              type  = " org.apache.struts.actions.ForwardAction "  
 
64              parameter  = " /author.html "     />  
 
65   
 
66            <  action  path  = " /author "  
 
67              type  = " org.springframework.web.struts.DelegatingActionProxy "  
 
68              name  = " authorForm "   scope  = " request "   parameter  = " method "   >  
 
69                <  forward  name  = " list "   path  = " /authorList.jsp "     />  
 
70                <  forward  name  = " edit "   path  = " /authorForm.jsp "     />  
 
71            </  action  >  
 
72          
 
73            <  action  path  = " /categorys "  
 
74              type  = " org.apache.struts.actions.ForwardAction "  
 
75              parameter  = " /category.html "     />  
 
76   
 
77            <  action  path  = " /category "  
 
78              type  = " org.springframework.web.struts.DelegatingActionProxy "  
 
79              name  = " categoryForm "   scope  = " request "   parameter  = " method "   >  
 
80                <  forward  name  = " list "   path  = " /categoryList.jsp "     />  
 
81                <  forward  name  = " edit "   path  = " /categoryForm.jsp "     />  
 
82            </  action  >  
 
83            <  action  path  = " /weblogs "  
 
84              type  = " org.apache.struts.actions.ForwardAction "  
 
85              parameter  = " /weblog.html "     />  
 
86   
 
87            <  action  path  = " /weblog "  
 
88              type  = " org.springframework.web.struts.DelegatingActionProxy "  
 
89              name  = " weblogForm "   scope  = " request "   parameter  = " method "   >  
 
90                <  forward  name  = " list "   path  = " /weblogList.jsp "     />  
 
91                <  forward  name  = " edit "   path  = " /weblogForm.jsp "     />  
 
92            </  action  >  
 
93   
 
94        </  action - mappings  >  
 
95   
 
96   
 
97        <!--    ================================  Message Resources Definitions   -->  
 
98   
 
99        <  message - resources  parameter  = " messages "     />  
100   
101        <!--    =======================================  Plug Ins Configuration   -->  
102   
103        <  plug - in
104           className  = " org.springframework.web.struts.ContextLoaderPlugIn "   >  
105            <  set - property  property  = " contextConfigLocation "  
106              value  = " /WEB-INF/action-servlet.xml "     />  
107        </  plug - in  >  
108   
109        <  plug - in  className  = " org.apache.struts.validator.ValidatorPlugIn "   >  
110            <  set - property  property  = " pathnames "  
111              value  = " /WEB-INF/validator-rules.xml,
112                                           / WEB - INF / validation.xml "    /> 
113        </  plug - in  >  
114    </  struts - config  >  
validation.xml 
 
1    <?  xml version = " 1.0 "  encoding = " UTF-8 "   ?>  
 
2    <!  DOCTYPE form - validation PUBLIC 
 
3       " -//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.1//EN "  
 
4       " http://jakarta.apache.org/commons/dtds/validator_1_1.dtd "   >  
 
5   
 
6    <  form - validation  >  
 
7        <  formset  >  
 
8            <  form  name  = " userForm "   >  
 
9                <  field  property  = " user.lastName "   depends  = " required "   >  
10                    <  arg0  key  = " user.lastName "   />  
11                </  field  >  
12            </  form  >  
13        </  formset  >  
14    </  form - validation  >
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值