print spaces with String.format()

You need to specify the minimum width of the field. String.format(“%” + numberOfSpaces + “s”, “”); Why do you want to generate a String of spaces of a certain length. If you want a column of this length with values then you can do: String.format(“%” + numberOfSpaces + “s”, “Hello”); which gives you numberOfSpaces-5 spaces … Read more

Spring boot test “No qualifying bean of type available”

The test environment needs to know where your beans are defined, so you have to tell it the location. In your test class, add the @ContextConfiguration annotation: @RunWith(SpringRunner.class) @AutoConfigureTestDatabase(replace = Replace.NONE) @DataJpaTest @ContextConfiguration(classes = {YourBeans.class, MoreOfYourBeans.class}) public class UserRepoTest { @Autowired private UserRepo userRepo = null; @Autowired private TestEntityManager entityManager = null;

How to add Log4J2 appenders at runtime programmatically?

There have been a number of requests to support better programmatic configuration for Log4j 2. Sorry it took so long. As of Log4j 2.4, API was added to log4j-core to facilitate programmatic configuration. The new ConfigurationBuilder API allows users to construct component definitions. With this API, there is no need to work directly with actual … Read more

How to get the size of a Stream after applying a filter by lambda expression?

When you get a stream from the list, it doesn’t modify the list. If you want to get the size of the stream after the filtering, you call count() on it. long sizeAfterFilter = locales.stream().filter(l -> l.getLanguage().equals(“en”)).count(); If you want to get a new list, just call .collect(toList()) on the resulting stream. If you are … Read more

Why has javax.persistence-api been replaced by jakarta.persistence-api in spring data jpa starter?

From Java Persistence API on Wikipedia: The Java Persistence API (JPA), in 2019 renamed to Jakarta Persistence, is a Java application programming interface specification that describes the management of relational data in applications using Java Platform, Standard Edition and Java Platform, Enterprise Edition/Jakarta EE. After Java EE was open sourced by Oracle and gave the … Read more