Java11 with Spring Boot2.1
Showing Japanese era
I just want to try if Spring Boot 2.1 works with Java11.
It is very easy, I do not have to do anything special without module-info.java.
I will try to use module-info.java next time. :-)
Result1
Result2
Spring Boot 2.1.2
build.gradle
buildscript { ext { springBootVersion = '2.1.2.RELEASE' } repositories { mavenCentral() } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") } } apply plugin: 'java' apply plugin: 'org.springframework.boot' apply plugin: 'io.spring.dependency-management' group = 'com.example' version = '1.0.0' sourceCompatibility = '1.11' targetCompatibility = '1.11' repositories { mavenCentral() } dependencies { implementation 'org.springframework.boot:spring-boot-starter-actuator' implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' implementation 'org.springframework.boot:spring-boot-starter-web' compileOnly 'org.projectlombok:lombok:1.18.4' runtimeOnly 'org.springframework.boot:spring-boot-devtools' testImplementation 'org.springframework.boot:spring-boot-starter-test' }
Gradle
use gradle5
Code without module-info.java
package com.example.japanesedatesample.controller; import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.chrono.JapaneseDate; import java.time.format.DateTimeFormatter; import java.util.Optional; @Slf4j @Controller public class JapaneseDateController { private static Logger logger = LoggerFactory.getLogger(JapaneseDateController.class); @RequestMapping("/") public String home() { return "test"; } @PostMapping("/show") public String show(String inDate, Model model) { logger.info("show inDate=[{}]", inDate); if (StringUtils.isEmpty(inDate)) { model.addAttribute("japaneseDate", "???"); } else { var formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); var localDate= LocalDate.parse(inDate, formatter); logger.info("localDate=[{}]", localDate); var japaneseDate = JapaneseDate.from(localDate); model.addAttribute("japaneseDate", japaneseDate); } model.addAttribute("inDate", inDate); return "test"; } }