Questions tagged [spring-environment]
28 questions
35
votes
8 answers
Inject spring bean dynamically
In a java-spring web-app I would like to be able to dynamically inject beans.
For example I have an interface with 2 different implementations:
In my app I'm using some properties file to configure injections:
#Determines the interface type the app…

forhas
- 11,551
- 21
- 77
- 111
19
votes
2 answers
Define Spring @PropertySource in xml and use it in Environment
In spring JavaConfig, I can define property source and inject into Environment
@PropertySource("classpath:application.properties")
@Inject private Environment environment;
How do I do that if in xml?
I am using context:property-placeholder, and on…

surajz
- 3,471
- 3
- 32
- 38
13
votes
2 answers
how to use Spring-EL in @Value when using constants to resolve a property
I'm trying to use a constant to define a property and then resolving it with the @Value annotation.
I defined the constant in an interface:
public interface InternalConstant{
public static final String JOB_NAME_PROPERTY =…

Hansjoerg Wingeier
- 4,274
- 4
- 17
- 25
5
votes
1 answer
Expose properties to the Spring Environment
I have a properties file that I'm registering with Spring through XML, using the property-placeholder element:
I can access properties using @Value annotations, e.g.…

Doches
- 3,276
- 2
- 19
- 26
3
votes
2 answers
Skipped XML bean definition file due to specified profiles [default] not matching
We have a Spring application deployed on tomcat, and it does not start.
The application error is as follows:
Caused by: org.springframework.beans.PropertyBatchUpdateException; nested
PropertyAccessExceptions (1) are:
PropertyAccessException 1:…

tjholmes66
- 1,850
- 4
- 37
- 73
3
votes
1 answer
log4j template file for multiple environments
I wish to have a single WAR file that will work in different environments (like dev, ci and prod) and spring environments largely cater to our use cases. log4j per environment is one of the outstanding items. As suggested in other answers, we can…

Kilokahn
- 2,281
- 1
- 25
- 50
2
votes
0 answers
Spring Boot Properties as Environment variables
I have come across some behaviour which seems inconsistent in how spring boot handles environment variables in application properties files vs configuration property classes. I am unsure whether this is a bug in spring or an error in my…

David
- 7,652
- 21
- 60
- 98
2
votes
1 answer
Reload spring beans excluding some beans
I would like to have the ability to periodically check some properties file and apply changes in my app accordingly.
In my java-spring application I'm checking periodically whether the properties file loaded from the file-system has…

forhas
- 11,551
- 21
- 77
- 111
2
votes
2 answers
@PropertySource and Application context name
I have an @Configuration class.
This class, has a @PropertySource.
I want to have one different property to each application.
Example:
@Configuration
@PropertySource("file:${my.properties-file}")
public class Config {
}
I want to configure each…

Beto Neto
- 3,962
- 7
- 47
- 81
2
votes
3 answers
Load different properties for development and deployment
I have a very common use case -- connect to different databases when my program is in development mode, in test mode, or in deployment mode.
The way I am doing it now, is I configure a data source, and pass it ${...} properties via bean:property…

f.khantsis
- 3,256
- 5
- 50
- 67
2
votes
1 answer
Properties Placeholder Inheritance in Spring 3.1
I'm trying to port our Custom Properties Placeholder with Spring's new Environment support but I can't figure out how to get what our current placeholder magic does.
What I would like is for a default bunch of property files to be read from…

Adam Gent
- 47,843
- 23
- 153
- 203
1
vote
2 answers
Spring Elements not showing under Eclipse Navigator
Although i have enabled Spring Elements and i can see that when i right click on my project, it doesn't show up under my project in Navigator.
I installed the necessary plugins also but still cant figure out the issue.
How can i fix this?

Avneet Hall
- 11
- 3
1
vote
1 answer
Will Spring enviroment.getProperty() access file every time or it will remember?
I have a Spring MVC application. I am using someprops.property file to get some global properties.
I am using Spring's Environment to get this.
@Autowired
private Environment env;
In some method
env.getProperty('some.prop');
My Question here is,…

Akshay
- 3,558
- 4
- 43
- 77
1
vote
1 answer
Set/Put value into Spring environment of Spring-boot for using later
Did there have any way to set or put some values into org.springframework.core.env.Environment?
We are using Spring-boot as below version.
org.springframework.boot
…

Bruce
- 647
- 2
- 12
- 30
1
vote
2 answers
Spring boot get command line args in configuration code
I got Spring boot with Spring batch project. Inside my BatchConfiguration I want to get command line arguments so I @Autowire Environment object and try to get my prop but I'm getting null.
After some debug I figured out that I can get all command…

Evgeny Makarov
- 1,417
- 1
- 21
- 41