Created
December 4, 2012 09:26
-
-
Save stuartgunter/4202153 to your computer and use it in GitHub Desktop.
Fluent Bean Definition in Spring
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.joda.time.DateTime; | |
@Configuration | |
public class AppConfig { | |
@Bean | |
public DateTime myFluentDate() { | |
return new DateTime() | |
.withYear(2012) | |
.withMonthOfYear(12) | |
.withDayOfMonth(1) | |
.withHourOfDay(6); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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