When using a Spock test, i have hardcoded some properties hardcoded into the spock test. The example is a JDBC url. I tried the @Value annotation together with a propertie file, but this seems not to work as my test has no stereotype. Are there any other solutions to inject property values?
@ContextConfiguration(locations = "classpath*:applicationContext-test.xml")
class RepositoryTest extends Specification {
@Shared sql = Sql.newInstance("jdbc:sqlserver:// - room - for - properties")
}
To use
PropertySourcesPlaceholderConfigurer
, add a@Configuration
class:Reference is here.
And then, in Spock:
The reason to use single quote is here.
And you probably need to add
@ContextConfiguration
to your Spock class:use jvm system properties "java -DdbUsername=bbbb"
@Shared properties cannot be injected, but something like this should work (with Spring 3):
This assumes that you have defined "databaseProperties" in your bean definition file: