I have a scenario where I will need some objects injecting at the start like logging, but then other objects injected on demand. What I don’t know is if in my console application, do I just call: in my Main function and then when I need another object, the type that I need on demand, do I use a Provider
CompletableFuture from Callable?
Today I experimented with the “new” CompletableFuture from Java 8 and found myself confused when I didn’t find a runAsync(Callable) method. I can do it myself like shown below, but why is this (to me very obvious and useful utility method) missing? Am I missing something? Answer You are supp…
Spring Rest Controller Return Specific Fields
I’ve been going through my head the best way to design a JSON API using Spring MVC. As we all know IO is expensive, and thus I don’t want to make the client make several API calls to get what they need. However at the same time I don’t necessarily want to return the kitchen sink. As an examp…
Error code -7 when trying to install release APK
I’ve taken all appropriate steps to create the release APK. (Demonstration of steps required) My device (Nexus 7 2012) is set to allow installs from unknown sources. I emailed the APK (app-release.apk) to myself and attempted to open it from GMail, as this should work. EDIT: I apologize, I also should h…
How configure connection existence check in C3P0?
I am using the below code to get Connection. I have used the c3p0 library for connection pooling. Now my question is, this code is not checking whether the connection is existing or not. Most likely this will get hit by the famous connection closed error after 8 hours. While I was using C3P0 with hibernate, t…
Jenkins CLI connection refused
When executing I’m getting connection refused for some reason. Jenkins version is 1580.3, user has the permissions on Jenkins server, cli jar is up-to-date and ssh public key is configured properly. Any idea what might be causing this? Here’s the stack trace if it will help: Answer If the connecti…
How to create a JavaFX Maven project in IntelliJ IDEA?
How can I open a JavaFX Maven project from scratch in IntelliJ IDEA? As there is no difference between a Java project and a JavaFx project, I want to open a dedicated JavaFX project (Selection JavaFX from create project Wizard) with Maven module included. Answer Although dated I’m answering this because…
How to get the full content of an XML file as a String using XmlStreamReader?
I’m in a part of an application where I have an access to the XmlStreamReader which is representing the XML file needed to be fully read into a String. Is there a way to obtain the XML content without …
How to inject property value using @Value into static fields
I have one property file config.properties which is configured using spring property placeholder. This is how it’s configured in my spring configuration file: Now I need to set its value to static field using @Value annotation. How can I achieve this? Answer The only way is to use setter for this value …
How JDBC Statement.setFetchsize exactly works
I want to implement this methods functionality in my custom JDBC driver. Which method from JDBC should I use to setMaxResults? If my query results is 1000 rows and I have set the value for setFetchSize=100, then what will be the results? It will return only 100 row or after returning first 100 it will get nex…