0

in my source code I need to set some properties, Database connection certifications on code level before the database connection establishes.

        System.setProperty("javax.net.ssl.trustStorePassword", keystorePassword);

edit - I tried it using java -Djavax.net.ssl.trustStorePassword=yourPassword on runtime, but I want to do it in code level.

1 Answer 1

2

I would suggest that you set this with a -D parameter when starting the JVM like in

java -Djavax.net.ssl.trustStorePassword=yourPassword ...

This goes along with the 12-factor-apps and makes your app easier to maintain

Sign up to request clarification or add additional context in comments.

8 Comments

That works, but my requirement is to do that in code level.
You could perhaps use @PostContruct within your @Config class like described here. But then you should not create a connection before the initialization is finished. Or when using spring boot you can do this in the main method of your app before starting Spring Boot. My advise would be to refactor the app so that it can work with System Properties from the environment
Really appreciate your help. In my project I do not use any configuration class for connecting to the db. I used persistent entity and spring repositories. I wrote and @postconstruct method in my persistent entity. but it did not work.
How do you start your application? You should be able to do something before you init the spring context.
currently I set them in main method before SpringApplication.run(SomeApplication.class, args); and It works perfectly. Im looking for a better way. and setting them through application properties.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.