E kūlia i ka nu’u. Strive to reach the highest.
1. Introduction to Hawaii
The Hawaii Framework is a Java framework for developing Spring based applications.
It provides production-ready features and integrations based best practices and experience to boost projects.
The Hawaii Framework is developed internally at QNH and is used in projects for medium and large enterprise customers.
1.1. Spring Boot
Combining Spring Boot and the Hawaii production-ready features and auto configuration brings even more power and simplicity to developers, without sacrificing flexibility.
The Hawaii Framework also provides various Spring Boot Starters to automatically include the needed dependencies and trigger the auto configuration of the Hawaii production-ready features.
But it is important to mention that most of the Hawaii features can also used without using Spring Boot. In that case the desired features need to be configured manually by defining the appropriate Spring beans inside the application’s context.
3. Hawaii Features
TODO.
3.4. Hawaii Time
HawaiiTime
is not merely a convenient wrapper to instantiate new java.time
date and time objects.
It provides an application wide java.time.Clock
reference which is particular useful for unit testing.
It is similar to Joda’s DateTimeUtils
which also allows setting a fixed current time.
However it is important to note that Joda’s DateTimeUtils
uses a static variable to store the current time.
HawaiiTime
does not take this approach. Instead the HawaiiTime
bean needs to be injected in any class that needs to
instantiate new date and time objects. This approach is more flexible and e.g. has the benefit that unit tests can be
run in parallel. See example usage below.
public class MyClass {
private HawaiiTime hawaiiTime;
public MyClass(HawaiiTime hawaiiTime) { (1)
this.hawaiiTime = hawaiiTime;
}
public void doSomethingWithDate() {
ZonedDateTime dateTime = this.hawaiiTime.zonedDateTime(); (2)
// ...
}
}
public class MyClassTests {
@Test
public void testDoSomethingWithDate() {
long millis = System.currentTimeMillis();
HawaiiTime hawaiiTime = new HawaiiTime();
hawaiiTime.useFixedClock(millis); (3)
MyClass myClass = new MyClass(hawaiiTime);
myClass.doSomethingWithDate();
// ...
}
}
1 | Inject the HawaiiTime bean. |
2 | Use the injected HawaiiTime bean to instantiate new date and time objects. |
3 | In unit tests a fixed clock can be used to manipulate and predict the exact current time. |
Another benefit of using HawaiiTime
is that a fixed time can be used in a running application
to test how it behaves on a given date or time.
Third-party libraries being used by the application do not use HawaiiTime and probably
instantiate date and time objects based on the System time.
|
Hawaii uses UTC
as default timezone but this can be changed by setting the hawaii.time.timezone
configuration property. The provided value will be parsed by java.time.ZoneId#of(String zoneId)
and supports different timezone formats like UTC
, Europe/Amsterdam
and GMT+1
.
The creation of the HawaiiTime
bean can also be disabled by setting hawaii.time.enabled
to false
.
Appendices
Appendix A: Hawaii application properties
Various properties can be specified inside your application.properties/application.yml
file or as command line switches.
This section provides a list of available Hawaii application properties.
# ===================================================================
# HAWAII PROPERTIES
#
# This sample file is provided as a guideline. Do NOT copy it in its
# entirety to your own application. ^^^
# ===================================================================
# HAWAII SPRING BOOT DEFAULTS
spring:
jackson:
date-format: com.fasterxml.jackson.databind.util.ISO8601DateFormat
property-naming-strategy: CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES
serialization:
indent-output: false
write-dates-as-timestamps: false
write-date-timestamps-as-nanoseconds: false
logging:
file: log/hawaii.log
level:
org.hawaiiframework: INFO
org.springframework: INFO
# HAWAII TIME
hawaii:
time:
enabled: true # Enable creation of the `HawaiiTime` bean.
timezone: UTC # The timezone to use like `UTC`, `Europe/Amsterdam` or `GMT+1`.
---
spring:
profiles: dev
jackson:
serialization.indent-output: true
logging:
level:
org.hawaiiframework: DEBUG
---
spring:
profiles: test
---
spring:
profiles: prod