I\'m fairly new to spring so excuse me if this is a dumb question. When I try to launch a program I get the following error: java.lang.IllegalArgumentException: Could
I know It is an old message , but i want to add my case.
If you use more than one profile(dev,test,prod...), check your execute profile.
in my case, the war file generated didn't pick up the properties file so had to clean install again in IntelliJ editor.
Hopefully it will be still helpful, the application.properties (or application.yml) file must be in both the paths:
containing the same property you are referring
For properties that need to be managed outside of the WAR:
<context:property-placeholder location="file:///C:/application.yml"/>
For example if inside application.yml are name
and id
Then you can create bean in runtime inside xml spring
<bean id="id1" class="my.class.Item">
<property name="name" value="${name}"/>
<property name="id" value="${id}"/>
</bean>
If you are using Spring 3.1 and above, you can use something like...
@Configuration
@PropertySource("classpath:foo.properties")
public class PropertiesWithJavaConfig {
@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
return new PropertySourcesPlaceholderConfigurer();
}
}
You can also go by the xml configuration like...
<?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"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd">
<context:property-placeholder location="classpath:foo.properties" />
</beans>
In earlier versions.
You are not reading the properties file correctly. The propertySource should pass the parameter as: file:appclient.properties
or classpath:appclient.properties
. Change the annotation to:
@PropertySource(value={"classpath:appclient.properties"})
However I don't know what your PropertiesConfig
file contains, as you're importing that also. Ideally the @PropertySource
annotation should have been kept there.