Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9065921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:37:29+00:00 2026-06-16T16:37:29+00:00

I have a Spring MVC that uses an external library which i have no

  • 0

I have a Spring MVC that uses an external library which i have no access to the code. This external library reads some properties using standard system.getProperty calls. I have to set these values before i use the service.

As my application is a Spring MVC application, i am not sure how to initialise these properties. Here is what i have done so far but i for some reason the values are always null.

I put the properties in a properties file /conf/config.properties

my.user=myuser
my.password=mypassowrd
my.connection=(DESCRIPTION=(LOAD_BALANCE=on)(ADDRESS=(PROTOCOL=TCP)(HOST=xxxx.xxxx.xxxx)(PORT=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=xxx.xxx.xxx)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=myService)))

I then added the following two lines in my applicationContext.xml

<context:annotation-config/>
<context:property-placeholder location="classpath*:conf/config.properties"/>    

I read the documentation that to setup up initialisation code, you can implement the InitializingBean interface so i implemented the interface and implemented the afterPropertiesSet() method.

private static @Value("${my.user}") String username;
private static @Value("${my.password}") String password;
private static @Value("${my.connection}") String connectionString;  

@Override
    public void afterPropertiesSet() throws Exception {     
        System.setProperty("username",username);
        System.setProperty("password",password);
        System.setProperty("connectionString",connectionString);
    } 

The problem is that the values are always null when the afterPropertiesSet() method is called.

  • Is the above approach the correct way of initializing code especially for controllers? What happens if a second call is made to the Controller?
  • Are the values null because of the initialisation? i.e. spring has not set them yet?
  • Is it possible to add the initialisation code away from the Controller?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T16:37:30+00:00Added an answer on June 16, 2026 at 4:37 pm

    Are you sure that the definition of your bean/controller is in the same spring context config file as where you have the property-placeholder definition?

    Have a look at Boris’ answer to this question: Spring @Value annotation in @Controller class not evaluating to value inside properties file

    If you wanted to move your code from your controller, you could add a component that listens for when spring has finished initializing, and hen calls the code:

    @Component
    public class ApplicationStartedListener implements ApplicationListener<ContextRefreshedEvent> {
    
        private static @Value("${my.user}") String username;
        private static @Value("${my.password}") String password;
        private static @Value("${my.connection}") String connectionString;
    
        public void onApplicationEvent(ContextRefreshedEvent event) {
            System.setProperty("username",username);
            System.setProperty("password",password);
            System.setProperty("connectionString",connectionString);
        } 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a website that uses JSP as its view technology (and Spring MVC
I have a spring web app that uses Hibernate and Velocity. It's an MVC
I have configured in following way that spring MVC app using Spring 3.1.1.RELEASE web.xml
I'm using spring MVC, and I have a custom authentication/security system that I had
I have a Spring MVC application which uses FreeMarker as View technology (But maybe
I have a Spring MVC webapp that uses Spring Security. I want to add
I am using Spring MVC and want to develop a website that uses REST
I have an ASP.Net MVC project that uses EF. I develop this application at
I have an ASP.NET MVC site, that uses a CommandService. This command service is
I have a Spring MVC app that uses JSP to render pages. Spring has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.