介绍

前一段时间观注了一下Spring4.0的一些特性,当中就有对Groovy配置的支持。因为临时还没有很深入的研究。所以举个小样例来说明一下怎样支持Groovy配置。

package shuai.study.spring.bean;

public class Gasoline {
private int capacity = 0; public Gasoline(int capacity) {
this.capacity = capacity;
} public int getCapacity() {
return this.capacity;
}
}
package shuai.study.spring.bean;

public class Car {
private String name = null;
private Gasoline gasoline = null; public Car(Gasoline gasoline) {
this.gasoline = gasoline;
} public void setName(String name) {
this.name = name;
} public void run() {
int capacity = gasoline.getCapacity(); if (gasoline.getCapacity() > 100) {
System.out.println("Gasoline capacity is " + capacity + ", " + this.name + " could start to run.");
} else {
System.out.println("Gasoline capacity is " + capacity + ", " + this.name + " is not enough to run.");
}
}
}

car-config.groovy configuration file:

import shuai.study.spring.bean.Car
import shuai.study.spring.bean.Gasoline beans {
/*
In class Car, we know that we defined variable gasoline as parameter of Car's constructor.
Here we point out this variable's class(i.e. Gasoline), meanwhile set parameter's value of
(Gasoline's) constructor
*/
gasoline(Gasoline, 80) /*
Define bean(i.e. car), and point out this bean's class(i.e. Car), meanwhile inject variable
gasoline to it. naturally we inject its variable(i.e. name) as well.
*/
car(Car, gasoline) {
name = "Benz"
}
}
package shuai.study.spring.bean;

import org.springframework.context.support.GenericGroovyApplicationContext;

public class CarApp {

	@SuppressWarnings("resource")
public static void main(String[] args) {
GenericGroovyApplicationContext context = new GenericGroovyApplicationContext("classpath:spring/bean/car-config.groovy"); Car car = (Car) context.getBean("car");
car.run();
}
}

Spring4.0支持Groovy配置的更多相关文章

  1. 丢弃重口味的xml配置--spring4用groovy配置bean(转)

    spring4之前,bean的配置可以主要分为两种方式,一种是使用基于xml,个人非常讨厌这种方式,因为明明一件很简单的事,放在xml中就会多了不少繁杂的信息.另一种方式,是从spring3.0开始, ...

  2. spring4.0之八:Groovy DSL

    4.0的一个重要特征就是完全支持Groovy,Groovy是Spring主导的一门基于JVM的脚本语言(动态语言).在spring 2.x,脚本语言通过 Java scripting engine在S ...

  3. Spring4.0编程式定时任务配置

    看过很多定时调度的配置,大多使用XML配置,觉得比较麻烦,也比较老套.这里介绍一种基于spring4.0注解编程式配置定时任务,简单清晰,使用方便.. 至于引入spring相关jar这里不多说,直接切 ...

  4. [转]Struts2.3.16.1+Hibernate4.3.4+Spring4.0.2 框架整合

    原文地址:http://blog.csdn.net/ycb1689/article/details/22928519 最新版Struts2+Hibernate+Spring整合 目前为止三大框架最新版 ...

  5. [CXF REST标准实战系列] 二、Spring4.0 整合 CXF3.0,实现测试接口

    Writer:BYSocket(泥沙砖瓦浆木匠) 微博:BYSocket 豆瓣:BYSocket Reprint it anywhere u want. 文章Points: 1.介绍RESTful架构 ...

  6. 项目ITP(六) spring4.0 整合 Quartz 实现动态任务调度

    前言 系列文章:[传送门] 项目需求: http://www.cnblogs.com/Alandre/p/3733249.html 上一博客写的是基本调度,后来这只能用于,像每天定个时间 进行数据库备 ...

  7. 项目ITP(五) spring4.0 整合 Quartz 实现任务调度

    前言 系列文章:[传送门] 项目需求: 二维码推送到一体机上,给学生签到扫描用.然后需要的是 上课前20分钟 ,幸好在帮带我的学长做 p2p 的时候,接触过.自然 quartz 是首选.所以我就配置了 ...

  8. [CXF REST标准实战系列] 二、Spring4.0 整合 CXF3.0,实现测试接口(转)

    转自:[CXF REST标准实战系列] 二.Spring4.0 整合 CXF3.0,实现测试接口 文章Points: 1.介绍RESTful架构风格 2.Spring配置CXF 3.三层初设计,实现W ...

  9. Spring4.0系列9-websocket简单应用

    http://wiselyman.iteye.com/blog/2003336 ******************************************* Spring4.0系列1-新特性 ...

随机推荐

  1. Devexpress Barmanager设置

    一,在bar的属性中有optionbar,可以做一些设置. 其中比较有用的是:1,去掉最右边的箭头:allowquickcustomization 改为false 2,去掉最左边的竖线:drawdra ...

  2. 页面点击关闭弹出提示js代码

    代码效果为: <script> window.onbeforeunload = function() { return "您好!\n我是abc\n —————————————— ...

  3. xamp配置多域名站点

    xampp配置多站点出现,htdocs目录和虚拟目录二者只能选其一的情况,我的xampp安装在D:\xampp\,默认web根目录在D:\xampp\htdocs,然后我在D:\magento安装了m ...

  4. Html5游戏框架createJs的简单用法

    声明:本文为原创文章,如需转载,请注明来源WAxes,谢谢!http://www.it165.net/pro/html/201403/11105.html 楼主记忆力不好,最近刚好用了一下create ...

  5. ubuntu 安装 open in teminal

    sudo apt-get install nautilus-open-terminalnautilus -q

  6. WAMP学习日记之:Apache发布php网站

    1.修改httpd.conf 文件,以便让Apache和php模块建立关联 2.配置php.ini文件 修改httpd.conf 文件,以便让Apache和php模块建立关联 如何让apache和ph ...

  7. DEDECMS 关键字不能小于2个字节!

    今天在做DEDECMS模板时,突然遇到了“关键字不能小于2个字节!”晕,是怎么回事呢?百度了一下,找到了答案,把他记录下来,方便自己日后再遇到这种问题时,可以查询: <form name=&qu ...

  8. 机器学习实验报告:利用3层神经网络对CIFAR-10图像数据库进行分类

    PS:这是6月份时的一个结课项目,当时的想法就是把之前在Coursera ML课上实现过的对手写数字识别的方法迁移过来,但是最后的效果不太好… 2014年 6 月 一.实验概述 实验采用的是CIFAR ...

  9. bzoj2395: [Balkan 2011]Timeismoney

    Description      有n个城市(编号从0..n-1),m条公路(双向的),从中选择n-1条边,使得任意的两个城市能够连通,一条边需要的c的费用和t的时间,定义一个方案的权值v=n-1条边 ...

  10. N.O.W,O.R,N.E.V.E.R--12days to LNOI2015

    双向链表 单调队列,双端队列 单调栈 堆 带权并查集 hash 表 双hash 树状数组 线段树合并 平衡树 Treap 随机平衡二叉树 Scapegoat Tree 替罪羊树 朝鲜树 块状数组,块状 ...