Why to use @AllArgsConstructor and @NoArgsConstructor together over an Entity?

The JPA specification requires that all persistent classes (@Entity) have a no-arg constructor, public or protected. (note that this is not necessarily true when dealing with some implementation like Hibernate, see this answer). This is needed because JPA uses the default constructor method to create a bean class using the reflection API. Indeed if your … Read more

Spring Boot 3 Micrometer Tracing Example

This blogpost from Spring Team will help to set it up: https://spring.io/blog/2022/10/12/observability-with-spring-boot-3 Also, I have come up with a sample Spring Boot 3 + Micrometer project here – https://github.com/kishorek/java/tree/main/spring-observability-demo. I am using Zipkin Brave as distributed tracing implementation. I have created a python service consumed by the Spring boot service. Please refer to the README.

Unable to start LiveReload server

In my case I have two Spring Boot services running simultaneously too. Of course disabling the live-reload completely will work, but there’s also a property you can set to choose a different port. Simply add the following to your application.yml (or properties equivalent). The default is 35729. spring: devtools: livereload: port: 35730

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 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.

spring-boot: Fatal error compiling: invalid target release: 17

You should check which Java version is configured in the JAVA_HOME. Use: mvn -version You should see something like this from mvn output $ mvn -version Apache Maven 3.8.5 (3599d3414f046de2324203b78ddcf9b5e4388aa0) Maven home: path\apache-maven-3.8.5 Java version: 17.0.3.1, vendor: Oracle Corporation, runtime: path\Java\jdk-17.0.3.1 Default locale: en_US, platform encoding: Cp1252 OS name: “windows 10”, version: “10.0”, arch: “amd64”, … Read more

Configuring base package for component scan in Spring boot test

Good to add the test config above I have the following in test config and any test case. I am new to spring boot test but it work. Let me know, if I am wrong. @Configuration @ComponentScan(“au.some.spring.package”) public class TestConfig { } @RunWith(SpringRunner.class) @EnableAutoConfiguration @SpringBootTest(classes= TestConfig.class) @TestPropertySource({“classpath:application.yml”, “classpath:env-${testing.env}.properties”}) public class DBDmoTest { @Autowired PartyRepository partyRepository; … Read more

tech