Spring4.0系列4-Meta Annotation(元注解)
Spring4.0系列6-Generic Qualifier(泛型限定)
Spring4.0系列7-Ordering Autowired Collections
更多正在编写中。。。
4.0的一个重要特征就是完全支持Groovy,Groovy是Spring主导的一门基于JVM的脚本语言(动态语言)。在spring 2.x,脚本语言通过 Java scripting engine在Spring中得到支持。而在4.0中,Groovy的变得更重要,Groovy可以替换xml和注解用来作为bean配置。
要使用Groovy,首先用maven下载Groovy的包,pom.xml文件中添加:
<dependency> <groupId>org.codehaus.groovy</groupId> <artifactId>groovy-all</artifactId> <version>2.1.8</version> </dependency>
下面使用xml,java annotation,groovy dsl实现相同功能的不同配置方式比较
XML
<jdbc:embedded-database id="dataSource" type="H2"> </jdbc:embedded-database> <bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="entityManagerFactory"> <property name="persistenceUnitName" value="persistenceUnit" /> <property name="dataSource" ref="dataSource" /> <property name="persistenceProviderClass" value="org.hibernate.ejb.HibernatePersistence"></property> <property name="packagesToScan"> <array> <value>com.hantsylabs.example.spring.model</value> </array> </property> <property name="jpaProperties"> <value> hibernate.format_sql=true hibernate.show_sql=true hibernate.hbm2ddl.auto=create </value> </property> </bean> <bean class="org.springframework.orm.jpa.JpaTransactionManager" id="transactionManager"> <property name="entityManagerFactory" ref="entityManagerFactory" /> </bean>
Annotation
@Configuration @ComponentScan(basePackages = { "com.hantsylabs.example.spring.dao","com.hantsylabs.example.spring.jpa" }) @EnableTransactionManagement(mode=AdviceMode.ASPECTJ) public class JpaConfig { @Bean public DataSource dataSource() { return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2).build(); } @Bean public LocalContainerEntityManagerFactoryBean entityManagerFactory() { LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean(); emf.setDataSource(dataSource()); emf.setPackagesToScan("com.hantsylabs.example.spring.model"); emf.setPersistenceProvider(new HibernatePersistence()); emf.setJpaProperties(jpaProperties()); return emf; } private Properties jpaProperties() { Properties extraProperties = new Properties(); extraProperties.put("hibernate.format_sql", "true"); extraProperties.put("hibernate.show_sql", "true"); extraProperties.put("hibernate.hbm2ddl.auto", "create"); return extraProperties; } @Bean public PlatformTransactionManager transactionManager() { return new JpaTransactionManager(entityManagerFactory().getObject()); } }
Groovy DSL
import org.apache.commons.dbcp.BasicDataSource import org.springframework.orm.jpa.JpaTransactionManager import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean import com.hantsylabs.example.spring.jpa.JpaConferenceDaoImpl beans { dataSource(BasicDataSource) { driverClassName = "org.h2.Driver" url = "jdbc:h2:mem:spring4-sandbox" username = "sa" password = "" } entityManagerFactory(LocalContainerEntityManagerFactoryBean){ persistenceProviderClass="org.hibernate.ejb.HibernatePersistence" dataSource=dataSource persistenceUnitName="persistenceUnit" packagesToScan=["com.hantsylabs.example.spring.model"] jpaProperties=[ "hibernate.format_sql":"true", "hibernate.show_sql":"true", "hibernate.hbm2ddl.auto":"create" ] } transactionManager(JpaTransactionManager){ entityManagerFactory=entityManagerFactory } conferenceDao(JpaConferenceDaoImpl){ } }
新书推荐《JavaEE开发的颠覆者: Spring Boot实战》,涵盖Spring 4.x、Spring MVC 4.x、Spring Boot企业开发实战。
京东地址:http://item.jd.com/11894632.html
当当地址:http://product.dangdang.com/23926195.html
亚马逊地址:http://www.amazon.cn/图书/dp/B01D5ZBFUK/ref=zg_bsnr_663834051_6
淘宝地址:https://item.taobao.com/item.htm?id=528426235744&ns=1&abbucket=8#detail
或自己在京东、淘宝、亚马逊、当当、互动出版社搜索自选。
相关推荐
本篇是哥自己根据《Gradle In Action》翻译的,继哥之前的Groovy DSL前传系列:用Groovy实现DSL领域定义语言(http://download.csdn.net/detail/vincentvalenlee/8382325)的后传翻译。通过gradle这个在项目构建领域...
apache-groovy-sdk-4.0.1下载
apache-groovy-3.0.8.zip apache官网的groovy3.0.8版本,希望大家多多下载,apache-groovy-3.0.8.zip apache官网的groovy3.0.8版本,希望大家多多下载,apache-groovy-3.0.8.zip apache官网的groovy3.0.8版本,希望...
spring-beans-groovy原码,可以直接导入Eclipse工程里面
微服务-spring-boot-groovy 使用 Spring Boot 和 Groovy 构建微服务创建这些项目是为了在当地的达拉斯 Groovy Grails 用户组会议上展示微服务架构这些服务使用您需要安装才能开始使用的各种外部服务。 您将需要安装 ...
apache-groovy-sdk-2.5.2.zip apache-groovy-sdk-2.5.2.zip
官网下载groovy sdk
spring-boot-groovy-config 使用Groovy文件配置Spring Boot应用程序。 这不仅允许以时髦的DSL方式指定属性,而且还允许(小的)逻辑并在配置内部重复使用(请注意,配置中的复杂逻辑通常不是一个好主意,但是在某些...
apache-groovy-sdk-2.4.4,for somebody who can not download
从Spring Framework 4.0开始,可以使用Groovy DSL定义外部bean配置。 这在概念上与使用XML bean定义相似,但是允许使用更简洁的语法。 使用Groovy还使您可以轻松地将bean定义直接嵌入到引导代码中。 类固醇上的XML...
apache-groovy-sdk-2.4.12.zip
jenkins集成sonarqube的groovy插件sonar-groovy-plugin-1.5.jar
apache-groovy-sdk-2.4.13,目前的最新版,刚下载的,供下载
apache-groovy-sdk-2.5.6.zip 截至 2019年04月19 日,Groovy 当前最稳定版本 请不要给我5星好评,因为好评会上涨积分!
groovy_sdk_2.5.8最新稳定版,groovy是gradle的底层语言,要深入了解gradle就得了解groovy,学groovy会java的学起来非常快。
vertx-web-groovy-dsl Groovy DSL声明Vert.x Web路由 如果您使用Groovy,则本项目旨在提供另一种方法来使用vert-web定义网络路由,这种方式更具Groovy风格。 最有趣的功能是能够使用嵌套闭包以嵌套方式声明路由器...
本文适合于不熟悉 Groovy,但想快速轻松地了解其基础知识的 Java开发人员。了解 Groovy 对 Java 语法的简化变形,学习 Groovy 的核心功能,例如本地集合、内置正则表达式和闭包。编写第一个 Groovy 类,然后学习如何...
本文适合于不熟悉 Groovy,但想快速轻松地了解其基础知识的 Java开发人员。了解 Groovy 对 Java 语法的简化变形,学习 Groovy 的核心功能,例如本地集合、内置正则表达式和闭包。编写第一个 Groovy 类,然后学习如何...
Groovy 2.4 is the latest stable version of Groovy. 截至2017.11.09 groovy最新最稳定版本 md5: ef84ac4fccc86bae171435bfdacedcbe 大小:34.8 MB
apache-groovy-docs-2.4.6.chm CHM文档