BAEL-6469 Code for the @Value Annotation Support on records in Spring improvement
This commit is contained in:
+10
@@ -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) {
|
||||
}
|
||||
+2
-2
@@ -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 {
|
||||
|
||||
+23
@@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user