Spring4.0支持Groovy配置
介绍
前一段时间观注了一下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配置的更多相关文章
- 丢弃重口味的xml配置--spring4用groovy配置bean(转)
spring4之前,bean的配置可以主要分为两种方式,一种是使用基于xml,个人非常讨厌这种方式,因为明明一件很简单的事,放在xml中就会多了不少繁杂的信息.另一种方式,是从spring3.0开始, ...
- spring4.0之八:Groovy DSL
4.0的一个重要特征就是完全支持Groovy,Groovy是Spring主导的一门基于JVM的脚本语言(动态语言).在spring 2.x,脚本语言通过 Java scripting engine在S ...
- Spring4.0编程式定时任务配置
看过很多定时调度的配置,大多使用XML配置,觉得比较麻烦,也比较老套.这里介绍一种基于spring4.0注解编程式配置定时任务,简单清晰,使用方便.. 至于引入spring相关jar这里不多说,直接切 ...
- [转]Struts2.3.16.1+Hibernate4.3.4+Spring4.0.2 框架整合
原文地址:http://blog.csdn.net/ycb1689/article/details/22928519 最新版Struts2+Hibernate+Spring整合 目前为止三大框架最新版 ...
- [CXF REST标准实战系列] 二、Spring4.0 整合 CXF3.0,实现测试接口
Writer:BYSocket(泥沙砖瓦浆木匠) 微博:BYSocket 豆瓣:BYSocket Reprint it anywhere u want. 文章Points: 1.介绍RESTful架构 ...
- 项目ITP(六) spring4.0 整合 Quartz 实现动态任务调度
前言 系列文章:[传送门] 项目需求: http://www.cnblogs.com/Alandre/p/3733249.html 上一博客写的是基本调度,后来这只能用于,像每天定个时间 进行数据库备 ...
- 项目ITP(五) spring4.0 整合 Quartz 实现任务调度
前言 系列文章:[传送门] 项目需求: 二维码推送到一体机上,给学生签到扫描用.然后需要的是 上课前20分钟 ,幸好在帮带我的学长做 p2p 的时候,接触过.自然 quartz 是首选.所以我就配置了 ...
- [CXF REST标准实战系列] 二、Spring4.0 整合 CXF3.0,实现测试接口(转)
转自:[CXF REST标准实战系列] 二.Spring4.0 整合 CXF3.0,实现测试接口 文章Points: 1.介绍RESTful架构风格 2.Spring配置CXF 3.三层初设计,实现W ...
- Spring4.0系列9-websocket简单应用
http://wiselyman.iteye.com/blog/2003336 ******************************************* Spring4.0系列1-新特性 ...
随机推荐
- 用Python高亮org-mode代码块
文章同时可在我的github blog上阅读:http://cheukyin.github.io/python/2014-08/pygments-highlight-src-export-html.h ...
- css清除浮动方法大全
清除浮动这个问题,做前端的应该再熟悉不过了,也是每一个web前台设计师 必须掌握的机能. 为什么浮动这么难? 因为浮动会使当前标签产生向上浮的效果,同时会影响到前后标签.父级标签的位置及 width ...
- 80端口被占用 PID = 4解决办法
请按照下面的步骤来运行命令:1. sc config http stat = demand2. reboot3. run the command(netsh http show servicestat ...
- PHP学习之中数组-遍历一维数组【2】
在PHP学习之中数组[1]中学会怎么创建一个数组,如果PHP学习之中数组[1]中的元素多的话,我们访问元素又是一个问题了,下面我们就使用for语句while,foreach来遍历我们的数组: < ...
- JS:window.onload的使用介绍
作者: 字体:[增加 减小] 类型:转载 时间:2013-11-13我要评论 window.onload在某些情况下还是比较实用的,比如加载时执行哪些脚本等等,下面有几个不错的示例,需要的朋友可以参考 ...
- STM32自带的bool型变量
这些标着位会让你的程序使用起来更方便. First you need to include "STM32f10x_type.h" /*布尔型变量*/typedef enum{FAL ...
- 总结iOS 8和Xcode 6的各种坑
模拟器的路径从之前的~/Library/Application Support/iPhone Simulator移动到了~/Library/Developer/CoreSimulator/Device ...
- Promise 让异步更优
每个异步方法都返回一个Promise 更优雅. then方法 每一个Promise 都有一个叫then 的方法, 接受一对callback 被解决时调用,resolve, 被拒绝 reje ...
- WIN版的Jenkins Master加入LINUX的SLAVE节点,并作C++程序的集成交付
这次深撸了一下JENKINS的配置,不敢说完全通了. 但对于整个体系,有了更新认识. 将LINUX作为SLAVE节点加入WIN的JENKINS里,网上有很多教程,依作即可. 在将相关任务分配给这个节点 ...
- 尼玛的,不学ORACLE RAC就不能叫高大上啊
刚才趁这段时间和机会,进去好好套弄一下. 我看不得会ORACLE人的嘴脸,于是,,,,我想试试~~~