JBakeのタグページが想定通り動いていない


タグのindexページは正しくタグを収集しているようですが、それぞれのタグ個別ページがちゃんと生成されていないですね… テンプレートは 標準のものそのまま使っているはずなのだけれど。

…
Read more ⟶

bashで標準出力をファイルに、標準エラー出力を画面とファイルに出力したい


Git の pre-push でテスト実行を行おうとした際、通常テスト実行ではデバッグログを出しているところを、エラーを表すものだけに絞って出すようにしようと考えました。

…
Read more ⟶

Lombokプラグインを入れているEclipseでMapStruct自動生成が機能しない


上記のコードのようにLombokとMapStructを併用しているプロジェクトを、 Lombokプラグインを適用したEclipseで読み込ませるとMapStructのコードが自動生成されません。 そのため、Eclipse上でJUnitテストを実行すると次のように java.lang.ClassNotFoundException: Cannot find implementation というエラーになります。

…
Read more ⟶

VSCodeでRustの整形ができない?


VSCodeでRustの勉強をしているのですが、現在、どうもコード整形機能が上手く働いていない…?

代替策としては、 rustfmt を使って、 cargo fmt コマンドで整形すれば良さそう。

…
Read more ⟶

cargo build で特定のバージョンの rustc を利用する


rustup run 1.15.1 cargo build

もちろん事前に使用するバージョンをインストールしておく必要がある:

rustup install 1.15.1

参考:

…
Read more ⟶

JBakeはじめました


個人的にMarkDownはあまり好きではなく(標準だと表現力が弱いし方言が多い!)、ずっとblogをAsciiDocで書く方法を模索していました。

…
Read more ⟶

Spring Bootは、セキュリティフィルタBeanを作っている分だけ、無料で認証できちまうんだ


要約

78.10 Add a Servlet, Filter, or Listener to an Application曰く。

any Servlet or Filter beans are registered with the servlet container automatically.

Spring Security 使った自前の認証フィルタを @Component 付けて作ったりなんかした際に意図しない URL path にも認証がかかってしまう。
んゴ。

…
Read more ⟶

h2-consoleとspring-boot-starter-securityと私


概要

spring-boot-starter-security を導入しても http://localhost:8080/h2-console にアクセスしたかった。

作業結果: https://github.com/yukihane/hello-java/tree/master/spring/h2-console-spring-security-example

手順

h2-console が使える依存関係を追加してプロジェクトセットアップ 8113d7

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
        </dependency>

h2-console を表示してみる 1b16dc

spring.h2.console.enabled=true
spring.datasource.generate-unique-name=false
create table greeting_table (
  message varchar(256) not null
);

(注: spring.datasource.generate-unique-name 設定は Spring Boot 2.3.0 からデフォルト値が変わったため必要になったもので、リンク先 Git リポジトリには含まれていません(参考))

…
Read more ⟶

spring-boot-starter-security を入れたら認証画面が!


WebSecurityConfigurerAdapter#configure(HttpSecurity) で form 認証を有効化しているのでこれをディスる。
WebSecurityConfigurerAdapterを継承した Spring コンポーネントをスキャン対象に含めれば良い。

…
Read more ⟶

ちょっと待って!そのUserDetails、本当に必要ですか?


概要

Spring Boot の認証を実装してみた系のサンプルでよく UserDetails や UserDetailsService が用いられているが、必然性が不明なものがほとんどである。
(おそらく当の実装者も理解していない1。)

…
Read more ⟶

ファイル出力先にServletContext#getRealPathを使うな


タイトルに書いたような、ファイル出力先として ServletContext#getRealPath を利用しているサンプルコードが見つかる、と聞いて検索してみたところ、日本語、非日本語にかかわらず確かにそのようなサンプルコードは散見されました。
例えば Qiita では(順不同):

…
Read more ⟶

元号が令和に変わったことを知らない人のための日付処理方法


問題

JapaneseDate.of(や LocalDate.of)を使うと厳密(strict)に検証されてしまう。
結果、例外が出る。

// 平成31年6月12日
final JapaneseDate today = JapaneseDate.of(JapaneseEra.HEISEI, 31, 6, 12);
System.out.println(today);
Exception in thread "main" java.time.DateTimeException: year, month, and day not valid for Era
	at java.base/java.time.chrono.JapaneseDate.of(JapaneseDate.java:231)
	at com.github.yukihane.datetime.App.main(App.java:21)

解決策

JapaneseChronology#resolveDate(や IsoChronology#resolveDate)を使えばゆるふわ(lenient)な検証でゆるしてくれたりも。

…
Read more ⟶

SimpleDateFormat もこれもうわかんねぇな


結果

1.8

H

11

平成

環境

1.8

java version "1.8.0_201"
Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)

11

openjdk version "11.0.2" 2019-01-15
OpenJDK Runtime Environment 18.9 (build 11.0.2+9)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.2+9, mixed mode)

コード

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.Date;
import java.util.Locale;

public class Main {

    public static void main(final String[] args) {
        final Date date = date(2010, 3, 4);
        final SimpleDateFormat format = new SimpleDateFormat("G", new Locale("ja", "JP", "JP"));
        System.out.println(format.format(date));
    }

    private static Date date(final int year, final int month, final int dayOfMonth) {
        final long time = LocalDate.of(year, month, dayOfMonth)
            .atStartOfDay(ZoneOffset.ofHours(9)).toEpochSecond() * 1000;
        return new Date(time);
    }
}

関連(しない)

関連(する)

From JDK 9 onwards, the default locale data is the data derived from the Unicode Consortium’s Common Locale Data Repository (CLDR). Please refer https://www.unicode.org/cldr/charts/33/by_type/date_&_time.japanese.html
The short display format for Heisei is 平成 in the ja locale in CLDR data. Hence the difference in the result.

…
Read more ⟶