Skip to content

Instantly share code, notes, and snippets.

@stuartgunter
Created December 4, 2012 09:26
Show Gist options
  • Save stuartgunter/4202153 to your computer and use it in GitHub Desktop.
Save stuartgunter/4202153 to your computer and use it in GitHub Desktop.
Fluent Bean Definition in Spring
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:sg="http://www.stuartgunter.org/schema/spring"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.stuartgunter.org/schema/spring http://www.stuartgunter.org/schema/spring/spring.xsd">
<sg:builder-factory id="myBean"
builder-class="org.joda.time.DateTime"
build-method="toDateTime">
<sg:with name="year" value="2012"/>
<sg:with name="monthOfYear" value="12"/>
<sg:with name="dayOfMonth" ref="1"/>
<sg:with name="hourOfDay" value="6"/>
</sg:builder-factory>
</beans>
import org.joda.time.DateTime;
@Configuration
public class AppConfig {
@Bean
public DateTime myFluentDate() {
return new DateTime()
.withYear(2012)
.withMonthOfYear(12)
.withDayOfMonth(1)
.withHourOfDay(6);
}
}
<dependency>
<groupId>org.stuartgunter</groupId>
<artifactId>spring-beans</artifactId>
<version>1.0.1</version>
</dependency>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment