Unable to load application properties in springboot











up vote
0
down vote

favorite












I have application related properties in my spring boot application. The strange issue is sometimes the properties load without any issues but most of the times they throw exception.



Here is my spring boot class annotated with @Configuration. Tried debugging the issue but could not find any reason for this weird behaviour.



@Configuration
public class RedisConfig {
private static final Logger logger = LoggerFactory.getLogger(RedisConfig.class);

@Value("${redisurl}")
private String redisURL;

@Value("${redisport}")
private String redisPort;

@Bean
public JedisConnectionFactory redisConnectionFactory() {

logger.info("--redisURL-" + redisURL);
logger.info("--redisPort-" + redisPort);

JedisConnectionFactory redisConnectionFactory = new JedisConnectionFactory();
redisConnectionFactory.setHostName(redisURL);
redisConnectionFactory.setPort(Integer.parseInt(redisPort));
logger.info("--connected to redis--");
return redisConnectionFactory;
}


redisurl=cst-prd-007
redisport=6379
redispassword=


Any help is appreciated.



Stacktrace:



Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.actuate.autoconfigure.redis.RedisHealthIndicatorConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'redisConfig': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'redisurl' in value "${redisurl}"
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:729)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:192)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1270)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1127)

Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'redisurl' in value "${redisurl}"
at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:172)
at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:124)
at org.springframework.core.env.AbstractPropertyResolver.doResolvePlaceholders(AbstractPropertyResolver.java:237)
at org.springframework.core.env.AbstractPropertyResolver.resolveRequiredPlaceholders(AbstractPropertyResolver.java:211)
at org.springframework.context.support.PropertySourcesPlaceholderConfigurer.lambda$processProperties$0(PropertySourcesPlaceholderConfigurer.java:175)
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveEmbeddedValue(AbstractBeanFactory.java:834)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1086)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1065)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:584)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:91)
at org.springframework.beans.factory.annotation.AutowiredAnnotationB


Edit:



I also tried doing this. Did not work



 @Autowired
Environment env;

@Bean
public JedisConnectionFactory redisConnectionFactory() {

logger.info("--redisURL-" + redisURL);
logger.info("--redisPort-" + redisPort);

redisURL = env.getRequiredProperty("redis.url");
redisPort = env.getRequiredProperty("redis.port");

JedisConnectionFactory redisConnectionFactory = new JedisConnectionFactory();
redisConnectionFactory.setHostName(redisURL);
redisConnectionFactory.setPort(Integer.parseInt(redisPort));
logger.info("--connected to redis--");
return redisConnectionFactory;
}


Issue solved after using the below approach



@Component
public class RedisConf {

@Value("${redis.url}")
String url;

@Value("${redis.port}")
int port;

public String getUrl() {
return url;
}

public void setUrl(String url) {
this.url = url;
}

public int getPort() {
return port;
}

public void setPort(int port) {
this.port = port;
}


}









share|improve this question
























  • Please share the stacktrace of the exception
    – Stephane Nicoll
    Nov 20 at 13:28










  • Are these properties set in application.properties? And when the exception is thrown can you please attach the stacktrace?
    – abj1305
    Nov 20 at 13:29










  • Added the stacktrace
    – wandermonk
    Nov 20 at 14:25






  • 1




    in your code, i don't think your keys match? redis.url would not be injectable by redisurl
    – pandaadb
    Nov 20 at 14:44










  • I am sorry i was trying multiple things so that confusion. I am using the exact name which are used in my properties file and the keys match with the annotated keys. Still i am getting the same issue.
    – wandermonk
    Nov 20 at 14:50















up vote
0
down vote

favorite












I have application related properties in my spring boot application. The strange issue is sometimes the properties load without any issues but most of the times they throw exception.



Here is my spring boot class annotated with @Configuration. Tried debugging the issue but could not find any reason for this weird behaviour.



@Configuration
public class RedisConfig {
private static final Logger logger = LoggerFactory.getLogger(RedisConfig.class);

@Value("${redisurl}")
private String redisURL;

@Value("${redisport}")
private String redisPort;

@Bean
public JedisConnectionFactory redisConnectionFactory() {

logger.info("--redisURL-" + redisURL);
logger.info("--redisPort-" + redisPort);

JedisConnectionFactory redisConnectionFactory = new JedisConnectionFactory();
redisConnectionFactory.setHostName(redisURL);
redisConnectionFactory.setPort(Integer.parseInt(redisPort));
logger.info("--connected to redis--");
return redisConnectionFactory;
}


redisurl=cst-prd-007
redisport=6379
redispassword=


Any help is appreciated.



Stacktrace:



Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.actuate.autoconfigure.redis.RedisHealthIndicatorConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'redisConfig': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'redisurl' in value "${redisurl}"
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:729)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:192)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1270)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1127)

Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'redisurl' in value "${redisurl}"
at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:172)
at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:124)
at org.springframework.core.env.AbstractPropertyResolver.doResolvePlaceholders(AbstractPropertyResolver.java:237)
at org.springframework.core.env.AbstractPropertyResolver.resolveRequiredPlaceholders(AbstractPropertyResolver.java:211)
at org.springframework.context.support.PropertySourcesPlaceholderConfigurer.lambda$processProperties$0(PropertySourcesPlaceholderConfigurer.java:175)
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveEmbeddedValue(AbstractBeanFactory.java:834)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1086)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1065)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:584)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:91)
at org.springframework.beans.factory.annotation.AutowiredAnnotationB


Edit:



I also tried doing this. Did not work



 @Autowired
Environment env;

@Bean
public JedisConnectionFactory redisConnectionFactory() {

logger.info("--redisURL-" + redisURL);
logger.info("--redisPort-" + redisPort);

redisURL = env.getRequiredProperty("redis.url");
redisPort = env.getRequiredProperty("redis.port");

JedisConnectionFactory redisConnectionFactory = new JedisConnectionFactory();
redisConnectionFactory.setHostName(redisURL);
redisConnectionFactory.setPort(Integer.parseInt(redisPort));
logger.info("--connected to redis--");
return redisConnectionFactory;
}


Issue solved after using the below approach



@Component
public class RedisConf {

@Value("${redis.url}")
String url;

@Value("${redis.port}")
int port;

public String getUrl() {
return url;
}

public void setUrl(String url) {
this.url = url;
}

public int getPort() {
return port;
}

public void setPort(int port) {
this.port = port;
}


}









share|improve this question
























  • Please share the stacktrace of the exception
    – Stephane Nicoll
    Nov 20 at 13:28










  • Are these properties set in application.properties? And when the exception is thrown can you please attach the stacktrace?
    – abj1305
    Nov 20 at 13:29










  • Added the stacktrace
    – wandermonk
    Nov 20 at 14:25






  • 1




    in your code, i don't think your keys match? redis.url would not be injectable by redisurl
    – pandaadb
    Nov 20 at 14:44










  • I am sorry i was trying multiple things so that confusion. I am using the exact name which are used in my properties file and the keys match with the annotated keys. Still i am getting the same issue.
    – wandermonk
    Nov 20 at 14:50













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have application related properties in my spring boot application. The strange issue is sometimes the properties load without any issues but most of the times they throw exception.



Here is my spring boot class annotated with @Configuration. Tried debugging the issue but could not find any reason for this weird behaviour.



@Configuration
public class RedisConfig {
private static final Logger logger = LoggerFactory.getLogger(RedisConfig.class);

@Value("${redisurl}")
private String redisURL;

@Value("${redisport}")
private String redisPort;

@Bean
public JedisConnectionFactory redisConnectionFactory() {

logger.info("--redisURL-" + redisURL);
logger.info("--redisPort-" + redisPort);

JedisConnectionFactory redisConnectionFactory = new JedisConnectionFactory();
redisConnectionFactory.setHostName(redisURL);
redisConnectionFactory.setPort(Integer.parseInt(redisPort));
logger.info("--connected to redis--");
return redisConnectionFactory;
}


redisurl=cst-prd-007
redisport=6379
redispassword=


Any help is appreciated.



Stacktrace:



Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.actuate.autoconfigure.redis.RedisHealthIndicatorConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'redisConfig': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'redisurl' in value "${redisurl}"
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:729)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:192)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1270)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1127)

Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'redisurl' in value "${redisurl}"
at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:172)
at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:124)
at org.springframework.core.env.AbstractPropertyResolver.doResolvePlaceholders(AbstractPropertyResolver.java:237)
at org.springframework.core.env.AbstractPropertyResolver.resolveRequiredPlaceholders(AbstractPropertyResolver.java:211)
at org.springframework.context.support.PropertySourcesPlaceholderConfigurer.lambda$processProperties$0(PropertySourcesPlaceholderConfigurer.java:175)
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveEmbeddedValue(AbstractBeanFactory.java:834)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1086)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1065)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:584)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:91)
at org.springframework.beans.factory.annotation.AutowiredAnnotationB


Edit:



I also tried doing this. Did not work



 @Autowired
Environment env;

@Bean
public JedisConnectionFactory redisConnectionFactory() {

logger.info("--redisURL-" + redisURL);
logger.info("--redisPort-" + redisPort);

redisURL = env.getRequiredProperty("redis.url");
redisPort = env.getRequiredProperty("redis.port");

JedisConnectionFactory redisConnectionFactory = new JedisConnectionFactory();
redisConnectionFactory.setHostName(redisURL);
redisConnectionFactory.setPort(Integer.parseInt(redisPort));
logger.info("--connected to redis--");
return redisConnectionFactory;
}


Issue solved after using the below approach



@Component
public class RedisConf {

@Value("${redis.url}")
String url;

@Value("${redis.port}")
int port;

public String getUrl() {
return url;
}

public void setUrl(String url) {
this.url = url;
}

public int getPort() {
return port;
}

public void setPort(int port) {
this.port = port;
}


}









share|improve this question















I have application related properties in my spring boot application. The strange issue is sometimes the properties load without any issues but most of the times they throw exception.



Here is my spring boot class annotated with @Configuration. Tried debugging the issue but could not find any reason for this weird behaviour.



@Configuration
public class RedisConfig {
private static final Logger logger = LoggerFactory.getLogger(RedisConfig.class);

@Value("${redisurl}")
private String redisURL;

@Value("${redisport}")
private String redisPort;

@Bean
public JedisConnectionFactory redisConnectionFactory() {

logger.info("--redisURL-" + redisURL);
logger.info("--redisPort-" + redisPort);

JedisConnectionFactory redisConnectionFactory = new JedisConnectionFactory();
redisConnectionFactory.setHostName(redisURL);
redisConnectionFactory.setPort(Integer.parseInt(redisPort));
logger.info("--connected to redis--");
return redisConnectionFactory;
}


redisurl=cst-prd-007
redisport=6379
redispassword=


Any help is appreciated.



Stacktrace:



Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.actuate.autoconfigure.redis.RedisHealthIndicatorConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'redisConfig': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'redisurl' in value "${redisurl}"
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:729)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:192)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1270)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1127)

Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'redisurl' in value "${redisurl}"
at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:172)
at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:124)
at org.springframework.core.env.AbstractPropertyResolver.doResolvePlaceholders(AbstractPropertyResolver.java:237)
at org.springframework.core.env.AbstractPropertyResolver.resolveRequiredPlaceholders(AbstractPropertyResolver.java:211)
at org.springframework.context.support.PropertySourcesPlaceholderConfigurer.lambda$processProperties$0(PropertySourcesPlaceholderConfigurer.java:175)
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveEmbeddedValue(AbstractBeanFactory.java:834)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1086)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1065)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:584)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:91)
at org.springframework.beans.factory.annotation.AutowiredAnnotationB


Edit:



I also tried doing this. Did not work



 @Autowired
Environment env;

@Bean
public JedisConnectionFactory redisConnectionFactory() {

logger.info("--redisURL-" + redisURL);
logger.info("--redisPort-" + redisPort);

redisURL = env.getRequiredProperty("redis.url");
redisPort = env.getRequiredProperty("redis.port");

JedisConnectionFactory redisConnectionFactory = new JedisConnectionFactory();
redisConnectionFactory.setHostName(redisURL);
redisConnectionFactory.setPort(Integer.parseInt(redisPort));
logger.info("--connected to redis--");
return redisConnectionFactory;
}


Issue solved after using the below approach



@Component
public class RedisConf {

@Value("${redis.url}")
String url;

@Value("${redis.port}")
int port;

public String getUrl() {
return url;
}

public void setUrl(String url) {
this.url = url;
}

public int getPort() {
return port;
}

public void setPort(int port) {
this.port = port;
}


}






spring-boot






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 at 16:13

























asked Nov 20 at 12:52









wandermonk

1,43321239




1,43321239












  • Please share the stacktrace of the exception
    – Stephane Nicoll
    Nov 20 at 13:28










  • Are these properties set in application.properties? And when the exception is thrown can you please attach the stacktrace?
    – abj1305
    Nov 20 at 13:29










  • Added the stacktrace
    – wandermonk
    Nov 20 at 14:25






  • 1




    in your code, i don't think your keys match? redis.url would not be injectable by redisurl
    – pandaadb
    Nov 20 at 14:44










  • I am sorry i was trying multiple things so that confusion. I am using the exact name which are used in my properties file and the keys match with the annotated keys. Still i am getting the same issue.
    – wandermonk
    Nov 20 at 14:50


















  • Please share the stacktrace of the exception
    – Stephane Nicoll
    Nov 20 at 13:28










  • Are these properties set in application.properties? And when the exception is thrown can you please attach the stacktrace?
    – abj1305
    Nov 20 at 13:29










  • Added the stacktrace
    – wandermonk
    Nov 20 at 14:25






  • 1




    in your code, i don't think your keys match? redis.url would not be injectable by redisurl
    – pandaadb
    Nov 20 at 14:44










  • I am sorry i was trying multiple things so that confusion. I am using the exact name which are used in my properties file and the keys match with the annotated keys. Still i am getting the same issue.
    – wandermonk
    Nov 20 at 14:50
















Please share the stacktrace of the exception
– Stephane Nicoll
Nov 20 at 13:28




Please share the stacktrace of the exception
– Stephane Nicoll
Nov 20 at 13:28












Are these properties set in application.properties? And when the exception is thrown can you please attach the stacktrace?
– abj1305
Nov 20 at 13:29




Are these properties set in application.properties? And when the exception is thrown can you please attach the stacktrace?
– abj1305
Nov 20 at 13:29












Added the stacktrace
– wandermonk
Nov 20 at 14:25




Added the stacktrace
– wandermonk
Nov 20 at 14:25




1




1




in your code, i don't think your keys match? redis.url would not be injectable by redisurl
– pandaadb
Nov 20 at 14:44




in your code, i don't think your keys match? redis.url would not be injectable by redisurl
– pandaadb
Nov 20 at 14:44












I am sorry i was trying multiple things so that confusion. I am using the exact name which are used in my properties file and the keys match with the annotated keys. Still i am getting the same issue.
– wandermonk
Nov 20 at 14:50




I am sorry i was trying multiple things so that confusion. I am using the exact name which are used in my properties file and the keys match with the annotated keys. Still i am getting the same issue.
– wandermonk
Nov 20 at 14:50












2 Answers
2






active

oldest

votes

















up vote
0
down vote













Instead of using @Value annotation, you can try using Environment from Spring Framework API.



Like this,



@Configuration
public class RedisConfig {
private static final Logger logger = LoggerFactory.getLogger(RedisConfig.class);

private String redisURL, redisPort;

@Autowired
private Environment env;

@Bean
public JedisConnectionFactory redisConnectionFactory() {

redisURL = env.getRequiredProperty("redisurl");
redisPort = env.getRequiredProperty("redisport");

JedisConnectionFactory redisConnectionFactory = new JedisConnectionFactory();
redisConnectionFactory.setHostName(redisURL);
redisConnectionFactory.setPort(Integer.parseInt(redisPort));
logger.info("--connected to redis--");
return redisConnectionFactory;
}





share|improve this answer





















  • I tried this it did not work. It was so mysterious to me so i posted on SO.
    – wandermonk
    Nov 20 at 15:14


















up vote
0
down vote













The issue is solved after using the below approach



@Component
public class RedisConf {

@Value("${redis.url}")
String url;

@Value("${redis.port}")
int port;

public String getUrl() {
return url;
}

public void setUrl(String url) {
this.url = url;
}

public int getPort() {
return port;
}

public void setPort(int port) {
this.port = port;
}


}





share|improve this answer





















  • docs.spring.io/spring-boot/docs/current/reference/html/… I'd recommend you check out the above. Not to mention spring already provides support for configurion redis via properties
    – Darren Forsythe
    Nov 20 at 16:27











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53393425%2funable-to-load-application-properties-in-springboot%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













Instead of using @Value annotation, you can try using Environment from Spring Framework API.



Like this,



@Configuration
public class RedisConfig {
private static final Logger logger = LoggerFactory.getLogger(RedisConfig.class);

private String redisURL, redisPort;

@Autowired
private Environment env;

@Bean
public JedisConnectionFactory redisConnectionFactory() {

redisURL = env.getRequiredProperty("redisurl");
redisPort = env.getRequiredProperty("redisport");

JedisConnectionFactory redisConnectionFactory = new JedisConnectionFactory();
redisConnectionFactory.setHostName(redisURL);
redisConnectionFactory.setPort(Integer.parseInt(redisPort));
logger.info("--connected to redis--");
return redisConnectionFactory;
}





share|improve this answer





















  • I tried this it did not work. It was so mysterious to me so i posted on SO.
    – wandermonk
    Nov 20 at 15:14















up vote
0
down vote













Instead of using @Value annotation, you can try using Environment from Spring Framework API.



Like this,



@Configuration
public class RedisConfig {
private static final Logger logger = LoggerFactory.getLogger(RedisConfig.class);

private String redisURL, redisPort;

@Autowired
private Environment env;

@Bean
public JedisConnectionFactory redisConnectionFactory() {

redisURL = env.getRequiredProperty("redisurl");
redisPort = env.getRequiredProperty("redisport");

JedisConnectionFactory redisConnectionFactory = new JedisConnectionFactory();
redisConnectionFactory.setHostName(redisURL);
redisConnectionFactory.setPort(Integer.parseInt(redisPort));
logger.info("--connected to redis--");
return redisConnectionFactory;
}





share|improve this answer





















  • I tried this it did not work. It was so mysterious to me so i posted on SO.
    – wandermonk
    Nov 20 at 15:14













up vote
0
down vote










up vote
0
down vote









Instead of using @Value annotation, you can try using Environment from Spring Framework API.



Like this,



@Configuration
public class RedisConfig {
private static final Logger logger = LoggerFactory.getLogger(RedisConfig.class);

private String redisURL, redisPort;

@Autowired
private Environment env;

@Bean
public JedisConnectionFactory redisConnectionFactory() {

redisURL = env.getRequiredProperty("redisurl");
redisPort = env.getRequiredProperty("redisport");

JedisConnectionFactory redisConnectionFactory = new JedisConnectionFactory();
redisConnectionFactory.setHostName(redisURL);
redisConnectionFactory.setPort(Integer.parseInt(redisPort));
logger.info("--connected to redis--");
return redisConnectionFactory;
}





share|improve this answer












Instead of using @Value annotation, you can try using Environment from Spring Framework API.



Like this,



@Configuration
public class RedisConfig {
private static final Logger logger = LoggerFactory.getLogger(RedisConfig.class);

private String redisURL, redisPort;

@Autowired
private Environment env;

@Bean
public JedisConnectionFactory redisConnectionFactory() {

redisURL = env.getRequiredProperty("redisurl");
redisPort = env.getRequiredProperty("redisport");

JedisConnectionFactory redisConnectionFactory = new JedisConnectionFactory();
redisConnectionFactory.setHostName(redisURL);
redisConnectionFactory.setPort(Integer.parseInt(redisPort));
logger.info("--connected to redis--");
return redisConnectionFactory;
}






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 20 at 14:36









Kumaresh Babu

7562820




7562820












  • I tried this it did not work. It was so mysterious to me so i posted on SO.
    – wandermonk
    Nov 20 at 15:14


















  • I tried this it did not work. It was so mysterious to me so i posted on SO.
    – wandermonk
    Nov 20 at 15:14
















I tried this it did not work. It was so mysterious to me so i posted on SO.
– wandermonk
Nov 20 at 15:14




I tried this it did not work. It was so mysterious to me so i posted on SO.
– wandermonk
Nov 20 at 15:14












up vote
0
down vote













The issue is solved after using the below approach



@Component
public class RedisConf {

@Value("${redis.url}")
String url;

@Value("${redis.port}")
int port;

public String getUrl() {
return url;
}

public void setUrl(String url) {
this.url = url;
}

public int getPort() {
return port;
}

public void setPort(int port) {
this.port = port;
}


}





share|improve this answer





















  • docs.spring.io/spring-boot/docs/current/reference/html/… I'd recommend you check out the above. Not to mention spring already provides support for configurion redis via properties
    – Darren Forsythe
    Nov 20 at 16:27















up vote
0
down vote













The issue is solved after using the below approach



@Component
public class RedisConf {

@Value("${redis.url}")
String url;

@Value("${redis.port}")
int port;

public String getUrl() {
return url;
}

public void setUrl(String url) {
this.url = url;
}

public int getPort() {
return port;
}

public void setPort(int port) {
this.port = port;
}


}





share|improve this answer





















  • docs.spring.io/spring-boot/docs/current/reference/html/… I'd recommend you check out the above. Not to mention spring already provides support for configurion redis via properties
    – Darren Forsythe
    Nov 20 at 16:27













up vote
0
down vote










up vote
0
down vote









The issue is solved after using the below approach



@Component
public class RedisConf {

@Value("${redis.url}")
String url;

@Value("${redis.port}")
int port;

public String getUrl() {
return url;
}

public void setUrl(String url) {
this.url = url;
}

public int getPort() {
return port;
}

public void setPort(int port) {
this.port = port;
}


}





share|improve this answer












The issue is solved after using the below approach



@Component
public class RedisConf {

@Value("${redis.url}")
String url;

@Value("${redis.port}")
int port;

public String getUrl() {
return url;
}

public void setUrl(String url) {
this.url = url;
}

public int getPort() {
return port;
}

public void setPort(int port) {
this.port = port;
}


}






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 20 at 16:12









wandermonk

1,43321239




1,43321239












  • docs.spring.io/spring-boot/docs/current/reference/html/… I'd recommend you check out the above. Not to mention spring already provides support for configurion redis via properties
    – Darren Forsythe
    Nov 20 at 16:27


















  • docs.spring.io/spring-boot/docs/current/reference/html/… I'd recommend you check out the above. Not to mention spring already provides support for configurion redis via properties
    – Darren Forsythe
    Nov 20 at 16:27
















docs.spring.io/spring-boot/docs/current/reference/html/… I'd recommend you check out the above. Not to mention spring already provides support for configurion redis via properties
– Darren Forsythe
Nov 20 at 16:27




docs.spring.io/spring-boot/docs/current/reference/html/… I'd recommend you check out the above. Not to mention spring already provides support for configurion redis via properties
– Darren Forsythe
Nov 20 at 16:27


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53393425%2funable-to-load-application-properties-in-springboot%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Wiesbaden

To store a contact into the json file from server.js file using a class in NodeJS

Marschland