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 7844295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:49:53+00:00 2026-06-02T16:49:53+00:00

I have a Spring 3.1 application, and I try to use a system variable

  • 0

I have a Spring 3.1 application, and I try to use a system variable in the context files. The variable “JAVA_MY_ENV” is defined on my System (on Windows, it is in the “System variables”, from the control panel).

In web.xml, I can use it as a variable and it works, it is successfully replaced by the actual value of the variable (let’s say “electrotype”) :

<listener>
    <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener> 
<context-param>
    <param-name>log4jConfigLocation</param-name>
    <param-value>classpath:log/${JAVA_MY_ENV}.log4j.properties</param-value>
</context-param>

I can also use it in my main “bean” context, to do an import, and it also works :

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:context="http://www.springframework.org/schema/context"       
        xmlns:tx="http://www.springframework.org/schema/tx" 
        xsi:schemaLocation="http://www.springframework.org/schema/beans
                            http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
                            http://www.springframework.org/schema/context
                            http://www.springframework.org/schema/context/spring-context-3.1.xsd
                            http://www.springframework.org/schema/tx
                            http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">

    <!-- (...) -->

    <import resource="classpath:spring/app-config.xml" />
    <import resource="classpath:spring/env/context-env-${JAVA_MY_ENV}.xml" />

</beans>

But In “app-config.xml”, one of my other context file, I try this and it doesn’t work :

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:context="http://www.springframework.org/schema/context"       
        xmlns:tx="http://www.springframework.org/schema/tx" 
        xsi:schemaLocation="http://www.springframework.org/schema/beans
                            http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
                            http://www.springframework.org/schema/context
                            http://www.springframework.org/schema/context/spring-context-3.1.xsd
                            http://www.springframework.org/schema/tx
                            http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">

    <bean id="appConfiguration" class="com.xxx.app.AppConfiguration">
        <constructor-arg value="${JAVA_MY_ENV}" />
    </bean>

</beans>

The com.xxx.app.AppConfiguration receives the String “${JAVA_MY_ENV}” as the constructor parameter, not the interpreted value of it!

I’m not sure to understand where the ${} variables are interpreted and where they are not.

Is there a way I can pass the interpreted ${JAVA_MY_ENV} value to my com.xxx.app.AppConfiguration constructor?

  • 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-02T16:49:57+00:00Added an answer on June 2, 2026 at 4:49 pm

    As of 3.0 in Spring you should be to inject values into properties

    @Value("#{ systemProperties['JAVA_MY_ENV'] }") 
    private String myVar;
    

    or

    <property name ="myVar" value="#{systemProperties['JAVA_MY_ENV']}"/>
    

    Alternatively you can look into using the PropertySourcesPlaceholderConfigurer or similar class. Creating this will tell spring how to look for variables. Often i make a number of property files as well so that environment and internal property file values are available to the app. e.g.

    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
      <property name="locations">
        <list>
            <value>classpath:someprops.properties</value>
        </list>
      </property>
      <property name="ignoreResourceNotFound" value="true" />
      <property name="searchSystemEnvironment" value="true" />
      <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
    

    A key element in the above example is the “searchSystemEnvironment” being set to true. This tells spring to use env variables (which is what you want)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Spring MVC application trying to use a rich domain model, with
I have a windows service application that runs as Local System, and I want
I have a spring application that uses an embedded Jetty instance. Since I am
I have a Spring application that I believe has some bottlenecks, so I'd like
I have a Spring application deployed in JBoss EAP server, using the following settings:
I have spring 2.5 application and several pages in the flow work perfectly -
I have a spring-hibernate application which is failing to map an object properly: basically
I have a Spring Web application with an applicationContext.xml loaded through a ContextLoaderListener in
I have a spring mvc application that I have broken up into separate maven
I have a Spring Web MVC application that I'd like to serve a large,

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.