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:
commit
5103f90fb5
|
@ -20,10 +20,12 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter</artifactId>
|
<artifactId>spring-boot-starter</artifactId>
|
||||||
|
<version>${spring-boot.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
<version>${spring-boot.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-lang</groupId>
|
<groupId>commons-lang</groupId>
|
||||||
|
@ -34,6 +36,7 @@
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<start-class>com.baeldung.properties.yaml.YamlApplication</start-class>
|
<start-class>com.baeldung.properties.yaml.YamlApplication</start-class>
|
||||||
|
<spring-boot.version>3.1.0</spring-boot.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</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;
|
package com.baeldung.properties.value;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest(classes = PriorityProvider.class)
|
@SpringBootTest(classes = PriorityProvider.class)
|
||||||
public class PriorityProviderIntegrationTest {
|
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…
Reference in New Issue