BAEL-3497 IntelliJ Cannot Resolve Spring Boot Configuration Properties (#8775)
Co-authored-by: Oskar <>
This commit is contained in:
parent
356ef842f0
commit
8be4255cbb
|
@ -43,6 +43,12 @@
|
||||||
<artifactId>httpcore</artifactId>
|
<artifactId>httpcore</artifactId>
|
||||||
<version>${httpcore.version}</version>
|
<version>${httpcore.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||||
|
<version>${configuration-processor.version}</version>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
|
@ -121,6 +127,7 @@
|
||||||
<guava.version>20.0</guava.version>
|
<guava.version>20.0</guava.version>
|
||||||
<httpcore.version>4.4.11</httpcore.version>
|
<httpcore.version>4.4.11</httpcore.version>
|
||||||
<resource.delimiter>@</resource.delimiter>
|
<resource.delimiter>@</resource.delimiter>
|
||||||
|
<configuration-processor.version>2.2.4.RELEASE</configuration-processor.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
package com.baeldung.configuration.processor;
|
||||||
|
|
||||||
|
import org.springframework.boot.context.properties.*;
|
||||||
|
import org.springframework.context.annotation.*;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@ConfigurationProperties(prefix = "com.baeldung")
|
||||||
|
public class CustomProperties {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The url to connect to.
|
||||||
|
*/
|
||||||
|
String url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The time to wait for the connection.
|
||||||
|
*/
|
||||||
|
private int timeoutInMilliSeconds = 1000;
|
||||||
|
|
||||||
|
|
||||||
|
public String getUrl() {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUrl(String url) {
|
||||||
|
this.url = url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTimeoutInMilliSeconds() {
|
||||||
|
return timeoutInMilliSeconds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTimeoutInMilliSeconds(int timeoutInMilliSeconds) {
|
||||||
|
this.timeoutInMilliSeconds = timeoutInMilliSeconds;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
package com.baeldung.configuration.processor;
|
||||||
|
|
||||||
|
import org.springframework.boot.*;
|
||||||
|
import org.springframework.boot.autoconfigure.*;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
public class DemoApplication {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(DemoApplication.class, args);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
package com.baeldung.configuration.processor;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.*;
|
||||||
|
import org.springframework.stereotype.*;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class PropertyBeanInjection {
|
||||||
|
|
||||||
|
private final CustomProperties customProperties;
|
||||||
|
|
||||||
|
PropertyBeanInjection(@Autowired CustomProperties customProperties) {
|
||||||
|
this.customProperties = customProperties;
|
||||||
|
}
|
||||||
|
|
||||||
|
String getUrl() {
|
||||||
|
return customProperties.getUrl();
|
||||||
|
}
|
||||||
|
|
||||||
|
int getTimeoutInMilliseconds() {
|
||||||
|
return customProperties.getTimeoutInMilliSeconds();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.baeldung.configuration.processor;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.*;
|
||||||
|
import org.junit.runner.*;
|
||||||
|
import org.springframework.beans.factory.annotation.*;
|
||||||
|
import org.springframework.boot.test.context.*;
|
||||||
|
import org.springframework.test.context.*;
|
||||||
|
import org.springframework.test.context.junit4.*;
|
||||||
|
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
@TestPropertySource("/configuration-processor.properties")
|
||||||
|
@SpringBootTest(classes = DemoApplication.class)
|
||||||
|
class PropertyBeanInjectionUnitTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private PropertyBeanInjection propertyBeanInjection;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void checkThatCustomPropertiesHaveTheCorrectValueFromPropertiesFile() {
|
||||||
|
Assertions.assertEquals("www.abc.test.com", propertyBeanInjection.getUrl());
|
||||||
|
Assertions.assertEquals(2000, propertyBeanInjection.getTimeoutInMilliseconds());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,2 @@
|
||||||
|
com.baeldung.url=www.abc.test.com
|
||||||
|
com.baeldung.timeout-in-milli-seconds=2000
|
Loading…
Reference in New Issue