BAEL-6469 Code for the @Value Annotation Support on records in Spring improvement
This commit is contained in:
		
							parent
							
								
									ee4923a29d
								
							
						
					
					
						commit
						38c71c91bb
					
				| @ -20,10 +20,12 @@ | ||||
|         <dependency> | ||||
|             <groupId>org.springframework.boot</groupId> | ||||
|             <artifactId>spring-boot-starter</artifactId> | ||||
|             <version>${spring-boot.version}</version> | ||||
|         </dependency> | ||||
|         <dependency> | ||||
|             <groupId>org.springframework.boot</groupId> | ||||
|             <artifactId>spring-boot-starter-web</artifactId> | ||||
|             <version>${spring-boot.version}</version> | ||||
|         </dependency> | ||||
|         <dependency> | ||||
|             <groupId>commons-lang</groupId> | ||||
| @ -34,6 +36,7 @@ | ||||
| 
 | ||||
|     <properties> | ||||
|         <start-class>com.baeldung.properties.yaml.YamlApplication</start-class> | ||||
|         <spring-boot.version>3.1.0</spring-boot.version> | ||||
|     </properties> | ||||
| 
 | ||||
| </project> | ||||
| @ -0,0 +1,10 @@ | ||||
| package com.baeldung.properties.value; | ||||
| 
 | ||||
| import org.springframework.beans.factory.annotation.Value; | ||||
| import org.springframework.context.annotation.PropertySource; | ||||
| import org.springframework.stereotype.Component; | ||||
| 
 | ||||
| @Component | ||||
| @PropertySource("classpath:values.properties") | ||||
| public record PriorityRecord(@Value("${priority:normal}") String priority) { | ||||
| } | ||||
| @ -1,13 +1,13 @@ | ||||
| package com.baeldung.properties.value; | ||||
| 
 | ||||
| import static org.assertj.core.api.Assertions.assertThat; | ||||
| 
 | ||||
| import org.junit.Test; | ||||
| import org.junit.runner.RunWith; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.boot.test.context.SpringBootTest; | ||||
| import org.springframework.test.context.junit4.SpringRunner; | ||||
| 
 | ||||
| import static org.assertj.core.api.Assertions.assertThat; | ||||
| 
 | ||||
| @RunWith(SpringRunner.class) | ||||
| @SpringBootTest(classes = PriorityProvider.class) | ||||
| public class PriorityProviderIntegrationTest { | ||||
|  | ||||
| @ -0,0 +1,23 @@ | ||||
| package com.baeldung.properties.value; | ||||
| 
 | ||||
| import org.junit.Test; | ||||
| import org.junit.runner.RunWith; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.boot.test.context.SpringBootTest; | ||||
| import org.springframework.test.context.junit4.SpringRunner; | ||||
| 
 | ||||
| import static org.assertj.core.api.Assertions.assertThat; | ||||
| 
 | ||||
| @RunWith(SpringRunner.class) | ||||
| @SpringBootTest(classes = PriorityRecord.class) | ||||
| public class PriorityRecordIntegrationTest { | ||||
| 
 | ||||
|     @Autowired | ||||
|     private PriorityRecord priorityRecord; | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenPropertyFile_WhenConstructorInjectionUsedInRecord_ThenValueInjected() { | ||||
|         assertThat(priorityRecord.priority()).isEqualTo("high"); | ||||
|     } | ||||
| 
 | ||||
| } | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user