Merge pull request #14156 from thibaultfaure/improvement/BAEL-6469

BAEL-6469 Code for the @Value Annotation Support on records in Spring…
This commit is contained in:
davidmartinezbarua 2023-06-05 14:12:15 -03:00 committed by GitHub
commit 5103f90fb5
4 changed files with 38 additions and 2 deletions

View File

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

View File

@ -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) {
}

View File

@ -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 {

View File

@ -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");
}
}