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!!

put on hold as off-topic by Ismael, shane, Richard Horrocks, Achala Dissanayake, flygoing 3 mins ago

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question does not appear to be about Ethereum, the decentralized application platform and smart contract enabled blockchain, within the scope defined in the help center." – Ismael, shane, Richard Horrocks, Achala Dissanayake, flygoing
If this question can be reworded to fit the rules in the help center, please edit the question.

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"
})
...

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