0

I am unable to read my application.properties file.Here is my code for application.properties:

eth.network.url="https://rinkeby.infura.io/v3/9ea96ecdf13c4756a99c19f4f34e679e";
WORKING_DIRECTORY= "~/testnet-keystore/UTC--2018-10-08T16-17-25.818111000Z--8a69dcd0dbaf0f076d663f366ec0bffad9a3cf2a.json";
WALLET_CREDENTIALS="*****";

I am trying to use it in my java file:

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.web3j.crypto.Credentials;
import org.web3j.crypto.WalletUtils;
import org.web3j.protocol.Web3j;
import org.web3j.protocol.http.HttpService;


@RestController

public class DeployController {
    private Web3j web3j;
    private Credentials credentials;
    public ProofOfExistence contract;



    @Value("${eth.network.url}")
    private String NETWORK_URL;

    @Value("${WORKING_DIRECTORY}")
    private String WORKING_DIRECTORY;

    @Value("${WALLET_CREDENTIALS}")
    private String WALLET_CREDENTIALS;

    @RequestMapping("/DeployController")
    public String BlogControllerDemo() throws Exception{

        web3j = Web3j.build(new HttpService(NETWORK_URL));
        credentials = WalletUtils.loadCredentials(WALLET_CREDENTIALS, WORKING_DIRECTORY);
        contract = ProofOfExistence.deploy(web3j, credentials, ProofOfExistence.GAS_PRICE,ProofOfExistence.GAS_LIMIT).send();
        String addr = contract.getContractAddress();
        return addr;


    }

}

When i run the above code it says:

Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'eth.network.url' in value "${eth.network.url}"
    at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:172) ~[spring-core-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:124) ~[spring-core-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.core.env.AbstractPropertyResolver.doResolvePlaceholders(AbstractPropertyResolver.java:237) ~[spring-core-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.core.env.AbstractPropertyResolver.resolveRequiredPlaceholders(AbstractPropertyResolver.java:211) ~[spring-core-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.context.support.PropertySourcesPlaceholderConfigurer.lambda$processProperties$0(PropertySourcesPlaceholderConfigurer.java:175) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.resolveEmbeddedValue(AbstractBeanFactory.java:839) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1086) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1065) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:584) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:91) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:373) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    ... 17 common frames omitted

Please help me figure out what I am missing here. Thank you!!

0

You need to source the properties file and only then you can use the properties file as below.

@Configuration
@PropertySource("classpath:foo.properties")
public class PropertiesWithJavaConfig {
    //...
}

Another way of registering a new properties file is using a placeholder to allow you to dynamically select the right file at runtime, example below:

@PropertySource({ 
  "classpath:persistence-${application}.properties"
})
...

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.