Populate a database with TestContainers in a SpringBoot integration test

The easiest way is to use JdbcDatabaseContainer::withInitScript Advantage of this solution is that script is run before Spring Application Context loads (at least when it is in a static block) and the code is quite simple. Example: static { postgreSQLContainer = new PostgreSQLContainer(“postgres:9.6.8”) .withDatabaseName(“integration-tests-db”) .withUsername(“sa”) .withPassword(“sa”); postgreSQLContainer .withInitScript(“some/location/on/classpath/someScript.sql”); postgreSQLContainer.start(); } JdbcDatabaseContainer is superclass of PostgreSQLContainer … Read more

Spring boot 3 – Jakarta and Javax

The answer will really depend on which specific libraries you’re using and how they interact with each other, but generally speaking trying to mix Java EE and Jakarta EE them would be a bad idea. As an example, if you’re writing a Spring MVC application then you’ll be using the DispatcherServlet. In Spring Framework 6 … Read more

By default, where does Spring Boot expect views to be stored?

The Solution I found the answer via trial-and-error, which turned out rather annoying. I hope someone can correct me if this conclusion is wrong, but it appears that Spring Boot does not like the string WEB-INF. I renamed the WEB-INF directory to view and changed the application.properties to the following and the view loaded successfully. … Read more

Spring Security in Spring Boot 3

Author: https://github.com/wilkinsona @Bean public SecurityFilterChain configure(HttpSecurity http) throws Exception { http .authorizeHttpRequests(requests -> requests .requestMatchers(new AntPathRequestMatcher(“/openapi/openapi.yml”)).permitAll() .anyRequest().authenticated()) .httpBasic(); return http.build(); } Source: https://github.com/spring-projects/spring-boot/issues/33357#issuecomment-1327301183 I recommend you use Spring Boot 3.0.0 (GA) right now, not RC version.

JSON parse error: Can not construct instance of io.starter.topic.Topic

For deserialisation purposes Topic must have a zero-arg constructor. For example: public class Topic { private String id; private String name; private String author; private String desc; // for deserialisation public Topic() {} public Topic(String id, String name, String author, String desc) { this.id = id; this.name = name; this.author = author; this.desc = desc; … Read more

Spring Boot Actuator hides property values in env endpoint

By default the /env endpoint will hide the value of any property with a key that, ignoring case, ends with password, secret, or key. You can customize this using the endpoints.env.keys-to-sanitize property. The value of this property should be a comma-separated list of suffixes or regexes to match against property names. For example, if you … Read more