This section explains Spring Data as a major environmental structures
- JPA Spring Data: committed to reducing the amount of development data access layer (DAO) is. Developers need to do is declare an interface persistence layer, the other to the Spring Data JPA to help you complete!
- Using Spring Data JPA persistence layer development carried out in four steps required:
- Configuring Spring integration JPA
- Spring Data configured in the Spring configuration file, so that Spring is the interface to create a proxy object declaration. Configure: after <jpa repositories>, will scan base-package specified when initialization Spring container package directory and its subdirectories, to inherit the Repository interface to create a proxy object or its sub-interfaces, and proxy object registered as SpringBean, business layer can be used as the object by the Spring of the automatic packaging.
- Statement persistence layer interface that inherits Repository. Interface Repository is a marker, it does not contain any methods, if necessary, Spring Data Repository other sub-interface can be realized, which defines some common CRUD, paging and related methods.
- Declarative approach needed in the interface. Spring Data will be based on given strategies to generate their implementation code.
- Environment to build
1. packages needed
① added spring pack
spring-aop-4.3.8.RELEASE.jar
spring-aspects-4.3.8.RELEASE.jar
spring-beans-4.3.8.RELEASE.jar
spring-context-4.3.8.RELEASE.jar
spring-core-4.3.8.RELEASE.jar
spring-expression-4.3.8.RELEASE.jar
spring-jdbc-4.3.8.RELEASE.jar
spring-orm-4.3.8.RELEASE.jar
spring-tx-4.3.8.RELEASE.jar
spring-web-4.3.8.RELEASE.jar
spring-webmvc-4.3.8.RELEASE.jar
com.springsource.net.sf.cglib-2.2.0.jar
com.springsource.org.aopalliance-1.0.0.jar
com.springsource.org.aspectj.weaver-1.6.8.RELEASE.jar
commons-logging-1.1.1.jar
② 加入hibernate包
antlr-2.7.7.jar
dom4j-1.6.1.jar
hibernate-commons-annotations-4.0.5.Final.jar
hibernate-core-4.3.11.Final.jar
hibernate-jpa-2.1-api-1.0.0.Final.jar
jandex-1.1.0.Final.jar
javassist-3.18.1-GA.jar
jboss-logging-3.1.3.GA.jar
jboss-logging-annotations-1.2.0.Beta1.jar
jboss-transaction-api_1.2_spec-1.0.0.Final.jar
③ 加jpa的包
hibernate-entitymanager-4.3.11.Final.jar
④ 加c3p0的包
c3p0-0.9.2.1.jar
hibernate-c3p0-4.3.11.Final.jar
mchange-commons-java-0.2.3.4.jar
⑤ 加mysql的驱动
mysql-connector-java-5.1.7-bin.jar
⑥加入springData
spring-data-commons-1.6.2.RELEASE.jar
spring-data-jpa-1.4.2.RELEASE.jar
⑦加入 slf4j-api-1.6.1.jar
2.Spring Bean profile
3. Database persistent classes
4.DAO
5. Test