springstrutsmybatis搭建开发环境.docx
- 文档编号:24683656
- 上传时间:2023-05-31
- 格式:DOCX
- 页数:19
- 大小:124.23KB
springstrutsmybatis搭建开发环境.docx
《springstrutsmybatis搭建开发环境.docx》由会员分享,可在线阅读,更多相关《springstrutsmybatis搭建开发环境.docx(19页珍藏版)》请在冰豆网上搜索。
springstrutsmybatis搭建开发环境
1.eclipse下新建一个web项目,项目结构图如下:
其中java文件夹存放以后编写的java文件,resource文件夹存放service、dao、struts的配置文件,sqlmap文件夹存放编程的sqlmap文件,datasource文件夹存放数据源配置的文件。
2.编写web.xml:
Java代码
1.
xml version="1.0" encoding="UTF-8"?
>
2. xsi="http: //www.w3.org/2001/XMLSchema-instance" xmlns=" xmlns: web=" xsi: schemaLocation=" id="WebApp_ID" version="2.5"> 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. org.springframework.web.context.request.RequestContextListener 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. log4j.properties 27. 28. 29. 30. org.springframework.web.util.Log4jConfigListener 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49.
3.applicationContext.xml文件的编写:
Java代码
1.
xml version="1.0" encoding="UTF-8"?
>
2. //www.springframework.org/schema/beans" 3. xmlns: xsi="http: //www.w3.org/2001/XMLSchema-instance" xmlns: context="http: //www.springframework.org/schema/context" 4. xsi: schemaLocation="http: //www.springframework.org/schema/beans 5. http: //www.springframework.org/schema/beans/spring-beans-3.0.xsd 6. http: //www.springframework.org/schema/context 7. http: //www.springframework.org/schema/context/spring-context-3.0.xsd"> 8. -- 导入数据源 --> 9. datasource/spring-datasource.xml"/> 10. 11. -- --> 12. com/water3/resource/user/service/spring-user-service.xml"/> 13. com/water3/resource/user/dao/spring-user-dao.xml"/> 14.//以上三个import是位于resource文件夹下配置文件,在此导入总配置文件中 15.
4.配置日志文件log4j.properties:
Java代码
1.### set log levels ###
2.log4j.rootLogger = DEBUG, stdout,D
3.### 输出到控制台 ###
4.log4j.appender.stdout = org.apache.log4j.ConsoleAppender
5.log4j.appender.stdout.Target = System.out
6.log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
7.log4j.appender.stdout.layout.ConversionPattern = %d{ABSOLUTE} %5p %c:
%L - %m%n
8.
9.### 输出到日志文件 ###
10.log4j.appender.D = org.apache.log4j.DailyRollingFileAppender
11.log4j.appender.D.File = logs/log.log
12.log4j.appender.D.Append = true
13.log4j.appender.D.Threshold = DEBUG
14.## 输出DEBUG级别以上的日志
15.log4j.appender.D.layout = org.apache.log4j.PatternLayout
16.log4j.appender.D.layout.ConversionPattern = %-d{yyyy-MM-dd HH:
mm:
ss} [ %t:
%r ] - [ %p ] %m%n
17.
18.### 保存异常信息到单独文件 ###
19.log4j.appender.D = org.apache.log4j.DailyRollingFileAppender
20.log4j.appender.D.File = logs/error.log
21.## 异常日志文件名
22.log4j.appender.D.Append = true
23.log4j.appender.D.Threshold = ERROR
24.## 只输出ERROR级别以上的日志!
!
!
25.log4j.appender.D.layout = org.apache.log4j.PatternLayout
26.log4j.appender.D.layout.ConversionPattern = %-d{yyyy-MM-dd HH:
mm:
ss} [ %t:
%r ] - [ %p ] %m%n
5.struts.xml文件引入公共配置:
Java代码
1.
xml version="1.0" encoding="UTF-8"?
>
2.
DOCTYPE struts PUBLIC
3."-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"
4."http:
//struts.apache.org/dtds/struts-2.1.7.dtd">
5.
6.
7.
-- 请求action时url以.do结束 -->
8.
9.
10.
11.
12.
-- 导入struts配置 -->
13.
14.
15.
16.
6.数据文件配置water3.properties:
Java代码
1.test.proxool.driver-class=com.mysql.jdbc.Driver
2.test.proxool.user=root
3.test.proxool.password=root
4.test.proxool.alias=test_proxool
5.test.proxool.driver-url=jdbc:
mysql:
//XXXX:
3306/test?
characterEncoding=utf-8&useUnicode=true
6.test.proxool.house-keeping-sleep-time=40000
7.test.proxool.house-keeping-test-sql=SELECT ''
8.test.proxool.maximum-connection-count=20
9.test.proxool.minimum-connection-count=5
10.test.proxool.maximum-connection-lifetime=18000000
11.test.proxool.simultaneous-build-throttle=5
12.test.proxool.recently-started-threshold=40000
13.test.proxool.overload-without-refusal-lifetime=50000
14.test.proxool.maximum-active-time=60000
15.test.proxool.verbose=true
16.test.proxool.trace=true
17.test.proxool.fatal-sql-exception=Fatal error
18.##最少连接数
19.test.proxool.prototype-count=5
20.test.proxool.statistics-log-level=ERROR
spring-datasource.xml
Java代码
1.
xml version="1.0" encoding="UTF-8"?
>
2. //www.springframework.org/schema/beans" 3. xmlns: xsi="http: //www.w3.org/2001/XMLSchema-instance" xmlns: context="http: //www.springframework.org/schema/context" 4. xsi: schemaLocation="http: //www.springframework.org/schema/beans 5. http: //www.springframework.org/schema/beans/spring-beans-3.0.xsd 6. http: //www.springframework.org/schema/context 7. http: //www.springframework.org/schema/context/spring-context-3.0.xsd"> 8. 9. property-placeholder location="classpath: datasource/*.properties" /> 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. --配置spring事务管理 --> 52. 53. class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> 54. 55. 56. 57. --配置backendSessionFactory --> 58. 59. 61. 62. datasource/water_datasource.xml"> 63. 64. 65. /sqlmap/**/sqlmap*.xml 66. 67. 68. 69. 70.
此处注意,mybatis需要配置一个别名文件water_datasource.xml,此文件一定要入如下配置。
Java代码
1.
xml versi
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- springstrutsmybatis 搭建 开发 环境