With latest jdbc drivers you can simply configure multiple host:port pairs in the url separated by comma:
jdbc:postgresql://host1:port1,host2:port2/test
It has only the most basic failover support. When a new connection is opened the hosts are tried in round-robin until a connection is successfully established.