Extjs5开发学习27服务端webspringhibernate配置文件的加入.docx
- 文档编号:11777371
- 上传时间:2023-06-02
- 格式:DOCX
- 页数:11
- 大小:221.48KB
Extjs5开发学习27服务端webspringhibernate配置文件的加入.docx
《Extjs5开发学习27服务端webspringhibernate配置文件的加入.docx》由会员分享,可在线阅读,更多相关《Extjs5开发学习27服务端webspringhibernate配置文件的加入.docx(11页珍藏版)》请在冰点文库上搜索。
Extjs5开发学习27服务端webspringhibernate配置文件的加入
Extjs5开发学习-27-服务端web,spring,hibernate配置文件的加入
我们前面创建项目的时候是一个javawebproject,现在在项目中需要加入spring,hibernate,sqlserver连接的jar包以及加入配置文件。
spring我现在使用的是3.1版本,hibernate使用的是3.0,具体的jar包以及一些附加包,请自行下载后加到工程中。
(所有的jar包在我的前一个博客中提供的演示软件中有)
一、在javaResources的src中加入一些package。
在src目录下建立文件hibernate.cfg.xml和log4j.properties。
hibenate的配置文件如下:
/application5.01/src/hibernate.cfg.xml
(使用的是sqlserver数据库,用其他数据库也可以。
)
[html] viewplain copy
1.
xml version="1.0" encoding="UTF-8"?
>
2.
DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
3. "
4.
5.
6.
7.
8.
sqlserver:
//10.211.55.5:
1433;databaseName=haiyu
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
系统日志配置文件:
/application5.01/src/log4j.properties。
[html] viewplain copy
1.log4j.rootCategory=error, console
2.
3.log4j.appender.console=org.apache.log4j.ConsoleAppender
4.log4j.appender.console.layout=org.apache.log4j.PatternLayout
5.log4j.appender.console.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
6.
7.log4j.logger.org.hibernate=error
8.log4j.logger.org.hibernate.SQL=error
9..jfok=error
10.log4j.logger.org.springframework=error
11.
12.#log4j.category.org.hibernate.type=debug
二、修改web.xml文件,加入spring的设置。
在WEB-INF目录下需要修改web.xml,并加入二个spring的配置文件applicationContext.xml和dispatcherServlet-servlet.xml。
web.xml的文件内容:
[html] viewplain copy
1.
xml version="1.0" encoding="UTF-8"?
>
2. xsi="http: //www.w3.org/2001/XMLSchema-instance" 3. xsi: schemaLocation=" 4. 5. version="2.5" xmlns=" 6. 7. -- spring 监听器 --> 8. 9. 10. 11. 12. -- spring 配置文件地址 --> 13. 14. 15. 16. /WEB-INF/applicationContext.xml 17. 18. 19. 20. -- Servlets --> 21. 22. -- spring MVC,其配置文件为 23. 24. 25. 26. 27. 28. 29. 30. 31. -- 用于匹配/rest/module/remove.do/{id} 之类的调用 --> 32. 33. 34. 35. -- 字符集编码过滤,防止某些乱码 --> 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. -- Default page to serve 180 --> 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69.
applicationContext.xml的内容:
[html] viewplain copy
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: p="http: //www.springframework.org/schema/p" 4. xmlns: tx="http: //www.springframework.org/schema/tx" xmlns: context="http: //www.springframework.org/schema/context" 5. xsi: schemaLocation=" 6. http: //www.springframework.org/schema/beans 7. http: //www.springframework.org/schema/beans/spring-beans-3.1.xsd 8. http: //www.springframework.org/schema/tx 9. http: //www.springframework.org/schema/tx/spring-tx-3.1.xsd 10. http: //www.springframework.org/schema/context 11. http: //www.springframework.org/schema/context/spring-context-3.1.xsd"> 12. 13. annotation-config /> 14. component-scan base-package="com.jfok"> 15. -- 将控制层排除在外,只扫描生成服务层的DAO层的类 --> 16. exclude-filter type="annotation" 17. expression="org.springframework.stereotype.Controller" /> 18. component-scan> 19. annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/> 20. 21. -- spring用于替换hibernateSessionFactory.java的sessionFactory --> 22. 23. class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> 24. hibernate.cfg.xml"> 25. 26. 27. 28. -- 事务管理器 --> 29. 30. class="org.springframework.orm.hibernate3.HibernateTransactionManager"> 31. 33. 34. 35. 36.
dispatcherServlet-servlet.xml的内容:
[html] viewplain copy
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: p="http: //www.springframework.org/schema/p" 4. xmlns: mvc="http: //www.springframework.org/schema/mvc" xmlns: context="http: //www.springframework.org/schema/context" 5. xsi: schemaLocation=" 6. http: //www.springframework.org/schema/beans 7. http: //www.springframework.org/schema/beans/spring-beans-3.1.xsd 8. 9. http: //www.springframework.org/schema/mvc 10. http: //www.springframework.org/schema/mvc/spring-mvc-3.1.xsd 11. 12. http: //www.springframework.org/schema/context 13. http: //www.springframework.org/schema/context/spring-context-3.1.xsd 14. "> 15. 16. -- ①: 对web包中的所有类进行扫描,以完成Bean创建和自动依赖注入的功能 , 只对标注为@Controller 的类进行分成,这些类是mvc的控制层 --> 17. component-scan base-package="com.jfok" use-default-filters="false"> 18. include-filter type="annotation" 19. expression="org.springframework.stereotype.Controller" /> 20. component-scan> 21. 22. -- ②: 启动Spring MVC的注解功能,完成请求和注解POJO的映射 --> 23. annotation-driven /> 24. 25. 26. class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" /> 27. 28. 29. class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" /> 30. 31. class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"> 32. 33. -- Configure the multipart resolver --> 34. 35. class="mons.CommonsMultipartResolver"> 36. -- one of the properties available; the maximum file size in bytes --> 37. 38. 39. 40.
(由于使用的spring的annotation注解进行开发,因此配置文件在以后开发过程中基本上不用修改。
)
三、将index.html改名为index.jsp。
四、在tomcat中发布此工程。
如果运行时没有出错信息,则说明所有的配置和jar包都正确了。
五、在浏览器中输入网址:
http:
//localhost:
8888/app/,应该显示原来做过的页面。
至此开发环境基本搭建完成,下面就是要加入一个个功能了。
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Extjs5 开发 学习 27 服务端 webspringhibernate 配置文件 加入