Reputation: 6189
People,do you know if its possible to get a properties file from maven dependency? More preciselly, i am using Spring 4, and i have my application.properties looking like this:
logging.level.org.springframework.web: INFO
logging.level.org.hibernate: ERROR
logging.level.com.example.movies: DEBUG
spring.config.location=example-backend-development-domain/src/main/resources/application.properties
This last line is not working. But what i want is to specify that there is this application.properties file which is inside resources folder inside a maven dependency (which has, by the way, the same parent of this actual project). So, this is that dependency:
<dependency>
<groupId>com.despegar.qc.example</groupId>
<artifactId>example-backend-development-domain</artifactId>
</dependency>
Do you know if this is even possible to make the spring.config.location line work? And in that case, do you know what would be the way to do that? Thanks in advance!
Upvotes: 1
Views: 327
Reputation: 29276
You can't load property files from logging configuration. Instead, create bean tag in configuration file and use it.
<bean id="myProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations">
<list>
<value>classpath*:application.properties</value>
</list>
</property>
</bean>
And you can use it in either way:
@Component
class MyClass {
@Value("${propertyName}")
private String myValue;
}
OR
@Component
class MyClass {
@Resource(name="myProperties")
private Properties myProperties;
@PostConstruct
public void init() {
// do whatever you need with properties
}
}
Upvotes: 1