当前位置: 代码迷 >> Web前端 >> ssh环境筹建
  详细解决方案

ssh环境筹建

热度:670   发布时间:2012-07-22 19:31:17.0
ssh环境搭建

所谓SSH,即struts+spring+hibernate的J2EE架构。

?

1.环境下载:Spring 3.1.1 + Struts 2.3.1.2 + Hibernate 4.1

?

http://struts.apache.org/download.cgi

?

http://www.springsource.org/download

?

http://in.relation.to/Bloggers/HibernateORM412Release?

?

?

重要配置:

?

Web.xml

  1. <?xml?version="1.0"?encoding="UTF-8"?>??
  2. <web-app?xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"??
  3. ????xmlns="http://java.sun.com/xml/ns/javaee"?xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"??
  4. ????xsi:schemaLocation="http://java.sun.com/xml/ns/javaee?http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"??
  5. ????id="WebApp_ID"?version="3.0">??
  6. ????<display-name>Eriloan_com</display-name>??
  7. ????<session-config>??
  8. ????????<session-timeout>30</session-timeout>??
  9. ????</session-config>??
  10. ????<context-param>??
  11. ????????<param-name>contextConfigLocation</param-name>??
  12. ????????<param-value>classpath:/spring-config/applicationContext-*.xml</param-value>??
  13. ????</context-param>??
  14. ????<listener>??
  15. ????????<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>??
  16. ????</listener>??
  17. ????<listener>??
  18. ????????<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>??
  19. ????</listener>??
  20. ????<listener>??
  21. ????????<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>??
  22. ????</listener>??
  23. ????<listener>??
  24. ????????<listener-class>org.apache.struts2.dispatcher.ng.listener.StrutsListener</listener-class>??
  25. ????</listener>??
  26. ????<filter>??
  27. ????????<filter-name>encodingFilter</filter-name>??
  28. ????????<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>??
  29. ????????<init-param>??
  30. ????????????<param-name>encoding</param-name>??
  31. ????????????<param-value>UTF-8</param-value>??
  32. ????????</init-param>??
  33. ????????<init-param>??
  34. ????????????<param-name>forceEncoding</param-name>??
  35. ????????????<param-value>true</param-value>??
  36. ????????</init-param>??
  37. ????</filter>??
  38. ????<filter-mapping>??
  39. ????????<filter-name>encodingFilter</filter-name>??
  40. ????????<url-pattern>/*</url-pattern>??
  41. ????</filter-mapping>??
  42. ????<filter>??
  43. ????????<filter-name>struts-cleanup</filter-name>??
  44. ????????<filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>??
  45. ????</filter>??
  46. ????<filter-mapping>??
  47. ????????<filter-name>struts-cleanup</filter-name>??
  48. ????????<url-pattern>/*</url-pattern>??
  49. ????</filter-mapping>??
  50. ????<filter>??
  51. ????????<filter-name>struts2</filter-name>??
  52. ????????<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>??
  53. ????</filter>??
  54. ????<filter-mapping>??
  55. ????????<filter-name>struts2</filter-name>??
  56. ????????<url-pattern>/*</url-pattern>??
  57. ????</filter-mapping>??
  58. ????<filter>??
  59. ????????<filter-name>openSessionInViewFilter</filter-name>??
  60. ????????<filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>??
  61. ????????<init-param>??
  62. ????????????<param-name>sessionFactoryBeanName</param-name>??
  63. ????????????<param-value>sessionFactory</param-value>??
  64. ????????</init-param>??
  65. ????????<init-param>??
  66. ????????????<param-name>singleSession</param-name>??
  67. ????????????<param-value>true</param-value>??
  68. ????????</init-param>??
  69. ????????<init-param>??
  70. ????????????<param-name>flushMode</param-name>??
  71. ????????????<param-value>AUTO</param-value>??
  72. ????????</init-param>??
  73. ????</filter>??
  74. ????<filter-mapping>??
  75. ????????<filter-name>openSessionInViewFilter</filter-name>??
  76. ????????<url-pattern>/*</url-pattern>??
  77. ????</filter-mapping>??
  78. ??
  79. ????<welcome-file-list>??
  80. ????????<welcome-file>index.jsp</welcome-file>??
  81. ????</welcome-file-list>??
  82. ????<error-page>??
  83. ????????<error-code>404</error-code>??
  84. ????????<location>/WEB-INF/errorPage/404.jsp</location>??
  85. ????</error-page>??
  86. ????<error-page>??
  87. ????????<error-code>500</error-code>??
  88. ????????<location>/WEB-INF/errorPage/500.jsp</location>??
  89. ????</error-page>??
  90. </web-app>??

Spring配置文件(applicationContext-common.xml):

  1. <?xml?version="1.0"?encoding="UTF-8"?>??
  2. <beans?xmlns="http://www.springframework.org/schema/beans"??
  3. ????xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"?xmlns:jee="http://www.springframework.org/schema/jee"??
  4. ????xmlns:tx="http://www.springframework.org/schema/tx"?xmlns:aop="http://www.springframework.org/schema/aop"??
  5. ????xmlns:p="http://www.springframework.org/schema/p"?xmlns:util="http://www.springframework.org/schema/util"??
  6. ????xmlns:tool="http://www.springframework.org/schema/tool"?xmlns:context="http://www.springframework.org/schema/context"??
  7. ????xsi:schemaLocation="http://www.springframework.org/schema/beans??
  8. ?????http://www.springframework.org/schema/beans/spring-beans.xsd??
  9. ?????http://www.springframework.org/schema/tx??
  10. ?????http://www.springframework.org/schema/tx/spring-tx.xsd??
  11. ?????http://www.springframework.org/schema/aop??
  12. ?????http://www.springframework.org/schema/aop/spring-aop.xsd??
  13. ?????http://www.springframework.org/schema/jee??
  14. ?????http://www.springframework.org/schema/jee/spring-jee.xsd??
  15. ?????http://www.springframework.org/schema/context??
  16. ?????http://www.springframework.org/schema/context/spring-context.xsd??
  17. ?????http://www.springframework.org/schema/util??
  18. ?????http://www.springframework.org/schema/util/spring-util.xsd??
  19. ?????http://www.springframework.org/schema/tool??
  20. ?????http://www.springframework.org/schema/tool/spring-tool.xsd"??
  21. ????default-lazy-init="true"?default-autowire="byName">??
  22. ??
  23. ????<bean?id="propertyConfigurer"??
  24. ????????class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">??
  25. ????????<property?name="locations">??
  26. ????????????<list>??
  27. ????????????????<value>classpath:/dataBaseInfo.properties</value>??
  28. ????????????</list>??
  29. ????????</property>??
  30. ????</bean>??
  31. ??
  32. ????<!--?<bean?id="dataSource"?class="org.springframework.jndi.JndiObjectFactoryBean"???
  33. ????????p:jndiName="java:comp/env/jdbc/MySSH"?/>?-->??
  34. ??
  35. ????<!--?BoneCP?-->??
  36. ????<bean?id="dataSource"?class="com.jolbox.bonecp.BoneCPDataSource"??
  37. ????????p:driverClass="${jdbc.driver}"?p:jdbcUrl="${jdbc.url}"?p:username="${jdbc.username}"??
  38. ????????p:password="${jdbc.password}"?p:idleConnectionTestPeriodInMinutes="${idleConnectionTestPeriodInMinutes}"??
  39. ????????p:idleMaxAgeInMinutes="${idleMaxAgeInMinutes}"??
  40. ????????p:maxConnectionsPerPartition="${maxConnectionsPerPartition}"??
  41. ????????p:minConnectionsPerPartition="${minConnectionsPerPartition}"??
  42. ????????p:partitionCount="${partitionCount}"?p:acquireIncrement="${acquireIncrement}"??
  43. ????????p:statementsCacheSize="${statementsCacheSize}"??
  44. ????????p:disableConnectionTracking="${disableConnectionTracking}"??
  45. ????????p:releaseHelperThreads="${releaseHelperThreads}"?destroy-method="close"?/>??
  46. ??????
  47. ????<bean?id="sessionFactory"??
  48. ????????class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"??
  49. ????????p:dataSource-ref="dataSource">??
  50. ??
  51. ????????<property?name="mappingDirectoryLocations">??
  52. ????????????<list>??
  53. ????????????????<value>classpath:/com/eriloan/web/test/bo/</value>??
  54. ????????????</list>??
  55. ????????</property>??
  56. ??
  57. ????????<property?name="hibernateProperties">??
  58. ????????????<props>??
  59. ????????????????<prop?key="hibernate.dialect">${hibernate.dialect}</prop>??
  60. ????????????????<prop?key="hibernate.show_sql">${hibernate.show_sql}</prop>??
  61. ????????????????<prop?key="hibernate.format_sql">${hibernate.format_sql}</prop>??
  62. ????????????????<prop?key="hibernate.use_sql_comments">${hibernate.use_sql_comments}</prop>??
  63. ????????????????<prop?key="hibernate.jdbc.batch_size">${hibernate.jdbc.batch_size}</prop>??
  64. ????????????????<prop?key="hibernate.max_fetch_depth">${hibernate.max_fetch_depth}</prop>??
  65. ????????????????<prop?key="hibernate.jdbc.fetch_size">${hibernate.jdbc.fetch_size}</prop>??
  66. ????????????????<prop?key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop>??
  67. ????????????????<prop?key="hibernate.cache.provider_class">${hibernate.cache.provider_class}</prop>??
  68. ????????????????<prop?key="hibernate.order_updates">${hibernate.order_updates}</prop>??
  69. ????????????????<prop?key="hibernate.query.factory_class">${hibernate.query.factory_class}</prop>??
  70. ????????????????<prop?key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop>??
  71. ????????????????<prop?key="hibernate.current_session_context_class">${hibernate.current_session_context_class}</prop>??
  72. <!--?????????????????<prop?key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>?-->??
  73. ????????????</props>??
  74. ????????</property>??
  75. ????</bean>??
  76. ??
  77. ????<bean?id="transactionManager"??
  78. ????????class="org.springframework.orm.hibernate4.HibernateTransactionManager"?/>??
  79. ??
  80. ????<bean?id="transactionInterceptor"??
  81. ????????class="org.springframework.transaction.interceptor.TransactionInterceptor"??
  82. ????????p:transactionManager-ref="transactionManager">??
  83. ????????<property?name="transactionAttributes">??
  84. ????????????<props>??
  85. ????????????????<prop?key="get*">PROPAGATION_REQUIRED,readOnly</prop>??
  86. ????????????????<prop?key="find*">PROPAGATION_REQUIRED,readOnly</prop>??
  87. ????????????????<prop?key="select*">PROPAGATION_REQUIRED,readOnly</prop>??
  88. ????????????????<prop?key="query*">PROPAGATION_REQUIRED,readOnly</prop>???????????????
  89. ????????????????<prop?key="sync*">PROPAGATION_REQUIRED</prop>??
  90. ????????????????<prop?key="finish*">PROPAGATION_REQUIRED</prop>??
  91. ????????????????<prop?key="add*">PROPAGATION_REQUIRED</prop>??
  92. ????????????????<prop?key="insert*">PROPAGATION_REQUIRED</prop>??
  93. ????????????????<prop?key="edit*">PROPAGATION_REQUIRED</prop>??
  94. ????????????????<prop?key="update*">PROPAGATION_REQUIRED</prop>??
  95. ????????????????<prop?key="save*">PROPAGATION_REQUIRED</prop>??
  96. ????????????????<prop?key="remove*">PROPAGATION_REQUIRED</prop>??
  97. ????????????????<prop?key="delete*">PROPAGATION_REQUIRED</prop>??
  98. ????????????????<prop?key="*">PROPAGATION_REQUIRED,-java.lang.Exception</prop>??
  99. ????????????</props>??
  100. ????????</property>??
  101. ????</bean>??
  102. ??
  103. ????<bean?id="ProxyCreator"??
  104. ????????class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"??
  105. ????????p:beanNames="*Service,*ServiceImpl"?p:interceptorNames="transactionInterceptor"?/>??
  106. ??
  107. ????<!--?数据库操作Bean?-->??
  108. ????<bean?id="dao"?class="dao.DaoImpl"?scope="singleton"?/>??
  109. ??
  110. ????<!--Service?原始Bean?-->??
  111. ????<bean?id="baseService"?class="service.BaseServiceImpl"?scope="singleton"?/>??
  112. ??????
  113. ????<!--Action?原始Bean?-->??
  114. ????<bean?id="baseAction"?class="action.BaseAction"?scope="prototype"?/>??
  115. ??
  116. </beans>??
  相关解决方案