I am working on a spring boot application. In this application, I have created application.properties as a spring bean using the following code
SCENARIO 1
Application.Properties
http.port =8080
ApplicationPropertyHandler
@PropertySource("config/application.properties")
@Component
public class ApplicationPropertyHandler
{
@Value("${http.port}")
private String nonSecurePort;
@Value("${https.port}" required=false)
private String securePort;
@Value("${server.servlet.context-path}")
private String contextPath;
@Value("${security.key}")
private String securityKey;
}
SCENARIO 2
When i secure application https.port will write to application.properties
Application.Properties
http.port =8080
https.port=8081
ApplicationPropertyHandler
@PropertySource("config/application.properties")
@Component
public class ApplicationPropertyHandler
{
@Value("${http.port}")
private String nonSecurePort;
@Value("${https.port}" required=false)
private String securePort;
@Value("${server.servlet.context-path}")
private String contextPath;
@Value("${security.key}")
private String securityKey;
Scenario 1: I got the below exception
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ApplicationPropertyHandler': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'https.port' in value "${https.port}"
Is it possible to run the Scenario 1 without having field https.port in application.properties?