没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
Spring Framework Cookbook i
Spring Framework Cookbook
Spring Framework Cookbook ii
Contents
1 Spring Framework Best Practices 1
1.1 Define singleton beans with names same as their class or interface names . . . . . . . . . . . . . . . . . . . . . 1
1.2 Place Spring bean configuration files under a folder instead of root folder . . . . . . . . . . . . . . . . . . . . . 1
1.3 Give common prefixes or suffixes to Spring bean configuration files . . . . . . . . . . . . . . . . . . . . . . . . 2
1.4 Avoid using import elements within Spring XML configuration files as much as possible . . . . . . . . . . . . . 2
1.5 Stay away from auto wiring in XML based bean configurations . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.6 Always externalize bean property values with property placeholders . . . . . . . . . . . . . . . . . . . . . . . . 3
1.7 Select default version-less XSD when importing namespace definitions . . . . . . . . . . . . . . . . . . . . . . . 3
1.8 Always place classpath prefix in resource paths . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.9 Create a setter method even though you use field level auto wiring . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.10 Create a separate service layer even though service methods barely delegate their responsibilities to correspond-
ing DAO methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.11 Use stereotype annotations as much as possible when employing annotation driven bean configuration . . . . . . 5
1.12 Group handler methods according to related scenarios in different Controller beans . . . . . . . . . . . . . . . . 6
1.13 Place annotations over concrete classes and their methods instead of their interfaces . . . . . . . . . . . . . . . . 6
1.14 Prefer throwing runtime exceptions instead of checked exceptions from service layer . . . . . . . . . . . . . . . 6
1.15 Manage transactions only in the service layer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.16 Mark transactions as readOnly=true when service methods only contain queries . . . . . . . . . . . . . . . . . . 7
1.17 Be aware of false positives in transactional ORM integration tests . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.18 Do not use DriverManagerDataSource . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.19 Either use NamedParameterJdbcTemplate or JdbcTemplate for your JDBC operations . . . . . . . . . . . . . . . 9
1.20 Use SessionFactory and EntityManager directly in your DAO beans . . . . . . . . . . . . . . . . . . . . . . . . 9
1.21 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2 Spring 4 Autowire Example 11
2.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.2 Usage of Autowire . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.3 Step by Step Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.3.1 Create the Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.3.2 Configure POM.xml (maven) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Spring Framework Cookbook iii
2.3.3 Create Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.3.4 Configure beans (applicationContext.xml) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2.3.5 Create the class that will use (injection) the service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2.3.6 Test it Out! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.4 Download the Eclipse project of this tutorial: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3 How to write Transactional Unit Tests with Spring 16
3.1 Create a new Maven Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.2 Add necessary dependencies in your project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.3 Create log4j.xml file in your project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
3.4 Prepare DDL and DML scripts to initialize database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
3.5 Write Domain Class, Service and DAO Beans . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
3.6 Configure Spring ApplicationContext . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
3.7 Write a transactional integration unit test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
3.8 Run the tests and observe the results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
3.9 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
3.10 Download the Source Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
4 Spring Framework JMSTemplate Example 32
4.1 Dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
4.2 Sending and Receiving Messages without JmsTemplate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
4.3 Configuring JmsTemplate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
4.4 Using JMSTemplate to produce messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
4.5 Using JMSTemplate to consume messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
4.6 Complete JmsTemplate example to send/receive messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
4.7 JmsTemplate with Default destination . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
4.8 JmsTemplate with MessageConverter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
4.9 Configuring MessageConverter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
4.10 Download the Eclipse Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
5 How to Start Developing Layered Web Applications with Spring 46
5.1 Create a new Maven WebApp project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
5.2 Add necessary dependencies in your project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
5.3 Create log4j.xml . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
5.4 Prepare DDL and DML scripts to initialize database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
5.4.1 schema.sql . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
5.4.2 data.sql . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
5.5 Write Domain Class, Service and DAO Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
5.5.1 Person.java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
5.5.2 PersonDao.java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Spring Framework Cookbook iv
5.5.3 JdbcPersonDao.java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
5.5.4 PersonService.java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
5.5.5 PersonServiceImpl.java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
5.6 Write Controller Classes and JSPs to handle UI logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
5.6.1 PersonListController and personList.jsp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
5.6.2 PersonCreateController and personCreate.jsp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
5.6.3 PersonUpdateController and personUpdate.jsp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
5.6.4 PersonDeleteController and personDelete.jsp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
5.7 Configure your web application to bootstrap with Spring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
5.7.1 WebAppConfig.java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
5.7.2 WebAppInitializer.java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
5.8 Configure your IDE to run Tomcat instance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
5.9 Run Tomcat instance and access your webapp through your browser . . . . . . . . . . . . . . . . . . . . . . . . 74
5.10 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
5.11 Download the Source Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
6 Angularjs and Spring Integration Tutorial 76
6.1 What is Spring? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
6.2 What Is Angular? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
6.3 Create a New Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
6.3.1 Maven dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
6.3.2 Web app java-based configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
6.3.3 SpringMVC controller and jsp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
6.3.4 Angularjs controllers and js files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
6.3.5 Build and run the application on tomcat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
6.4 Download the source code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
7 Spring MVC Application with Spring Security Example 84
7.1 Introduction to Spring Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
7.2 Project Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
7.3 Project Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
7.4 Download the Source Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
8 Spring MVC Hibernate Tutorial 94
8.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
8.2 Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
8.3 Spring MVC Framework . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
8.4 Hibernate For Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
8.5 Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
8.5.1 Maven Project and POM dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
剩余193页未读,继续阅读
资源评论
yinkaisheng-nj
- 粉丝: 763
- 资源: 6953
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Assignment2(4).ipynb
- 用pytorch框架实现的油井时间序列动态预测的模型,其中包含一些传统的时间序列预测方法 .zip
- TimesNet作为一般时间序列分析强大的基础模型 在长短期预测、插补、异常检测和分类5个主流任务上取得了一致的前沿成果.zip
- 实现结构体序列化和反序列化工具类CSearchive,支持基本类型,C++STL容器以及对象 .zip
- 时间序列遥感变化检测.zip
- 时间序列数据集收集以及数据分析.zip
- 时间序列分析ARIMA预测模型.zip
- 深度学习- 时间序列预测.zip
- 计算给定时间序列的平均值、方差、概率分布(大致的分布)、自协方差函数.zip
- 基于spring boot上的注解缓存,自带轻量级缓存管理页面.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功