Spring Bean Properties file
Okay, I'm confused here.
I have a properties file with some SQL scripts that I want to store at startup (using Spring MVC servlet container in Tomcat) for later use. Well I think I have the syntax for that down in the *-servlet.xml:
<util:properties
id="findQueries"
location="classpath:resources/FindQueries.properties" />
but I'm not sure how to access it programmatically. I really only need one query from this file in one function of a service-layer class at this point.
I'm fairly new开发者_如何学Python to Spring in general, so I'm definitely not set in my ways. Any suggestions of how to do this better / different will be considered.
Thanks all!
Obviously there is more than a dozen ways of doing this, Easiest way of doing this using @Value autowiring..
@Value("#{findQueries.queryKey}")
String query;
One other way of doing is to autowire the properties and then lookup for the key...
You can hook up your properties object for where you need it, by injecting it (for example into your controller class):
@Autowired()
@Qualifier("findQueries")
private Properties findQueries;
private void setFindQueries(Properties findQueries) {
this.findQueries = findQueries;
}
public void someotherMethod() {
findQueries.getProperty(...)
}
精彩评论