Category Archives: Java

What Is Spring Boot?

Spring Boot is a framework created by Pivotal. Spring Boot is very popular in java community because this framework can make it easy to create stand-alone web application. This framework is designed to simplify the bootstrapping and development of a new Spring application. Developers just need a very little Spring configuration to run web application, because the framework takes an… Read More »

Spring Data MongoDB – Upsert

In this tutorial i will share to you how to use UpSert operation in spring data mongoDB. If no document that matches the query, a new document is created by combining the query and update object. @Autowired private MongoTemplate mongoTemplate; //search a document that doesn’t exist Query query = new Query(); query.addCriteria(Criteria.where(“id”).is(“cimblo”)); Update update = new Update(); update.set(“age”,… Read More »

Spring Data MongoDB – Save Or Update

In this tutorial you will learn how to save or update data into database using spring data mongoDB. Spring Data MongoDB – Save Or Update First declare “Mongo Template”, then do save or update : @Autowired private MongoTemplate mongoTemplate; Mongo Template Save User user = new User(); user.setName(“cimblo”); user.setAge(99); //save data with save() function mongoTemplate.save(userTest1); Mongo Template Update… Read More »

Spring RestTemplate With Cookie In Header

Spring rest template hit endpoint with cookie in header can be like this: RestTemplate restTemplate = new RestTemplate(); HttpHeaders headers = new HttpHeaders(); headers.setAccept(Collections.singletonList(MediaType.ALL)); headers.add(“Cookie”, “ID=SPRING-JAVA”); HttpEntity entity = new HttpEntity<>(headers); ResponseEntity response = restTemplate.exchange( “https://www.cimblo.com”, HttpMethod.GET, entity, String.class); Spring RestTemplate With Cookie In Header In this example i’m using java 8 and spring boot version 1.5.8 with… Read More »

Open URL On Web Browser With JAVA (Linux, Mac, Windows)

If you need to open link on browser with java code, you can do with this code. Runtime rt = Runtime.getRuntime(); String url = “https://www.cimblo.com“; try { rt.exec(“open ” + url); } catch (IOException e) { e.printStackTrace(); } Open URL On Web Browser With JAVA (Linux, Mac, Windows) That code currently will work on Linux, Mac, Ubuntu and… Read More »

Spring Data MongoDB LIKE Query Insensitive Case ‘%%’

With spring data mongoDB you can do “LIKE QUERY” like example below. Query query = new Query(); query.addCriteria(Criteria.where(“name”).regex(“yourString”, “i”)); mongoTemplate.find(query, CodingExample.class) Spring Data MongoDB LIKE Query Insensitive Case Spring Data MongoDB The Spring Data MongoDB project provides integration with the MongoDB document database. Key functional areas of Spring Data MongoDB are a POJO centric model for interacting with… Read More »

AsyncRequestTimeoutException in Spring Boot

If you using asynchronous programming with observable streams in spring boot, i suggest you to setup async request timeout because default async request timeout in spring boot 2.0 is 10 second. You will got an exception (AsyncRequestTimeoutException) when request is more than 10 second. AsyncRequestTimeout My suggestion is 60s or 120s (s mean second) : spring.mvc.async.request-timeout=60s That is how to… Read More »

Convert Array to List In Java 8

In java 8 you can easily to convert array to list with stream. Convert Array to List In Java 8 For example: String[] array = new String[10]; List<String> listCollection = Arrays.stream(array).collect(Collectors.toList()); ArrayList<String> arrayListCollection = Arrays.stream(array).collect(Collectors.toCollection(ArrayList::new)); Set<String> setCollection = Arrays.stream(array).collect(Collectors.toSet()); HashSet<String> hashSetCollection = Arrays.stream(array).collect(Collectors.toCollection(HashSet::new)); TreeSet<String> treeSetCollection = Arrays.stream(array).collect(Collectors.toCollection(TreeSet::new)); LinkedList<String> linkedListCollection = Arrays.stream(array).collect(Collectors.toCollection(LinkedList::new)); LinkedHashSet<String> linkedHashSetCollection = Arrays.stream(array).collect(Collectors.toCollection(LinkedHashSet::new)); ArrayDeque<String> arrayDequeCollection =… Read More »